merge in oc-release history after reset to master
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 57d47fc..64b6b86 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -59,7 +59,7 @@
android:label="@string/settings_label">
<activity
- android:name=".HomepageActivity"
+ android:name=".home.HomepageActivity"
android:label="@string/settings_label"
android:launchMode="singleTask"
android:exported="true">
@@ -93,7 +93,7 @@
android:name=".wifi.WifiSettingsActivity"
android:label="@string/wifi_settings"
android:theme="@style/CarSettingTheme"
- android:icon="@drawable/ic_settings_wireless">
+ android:icon="@drawable/ic_settings_wifi">
<intent-filter android:priority="1">
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
@@ -113,7 +113,7 @@
android:name=".wifi.WifiDetailActivity"
android:label="@string/wifi_settings"
android:theme="@style/CarSettingTheme"
- android:icon="@drawable/ic_settings_wireless">
+ android:icon="@drawable/ic_settings_wifi">
<intent-filter android:priority="1">
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
@@ -127,7 +127,7 @@
android:name=".wifi.AddWifiActivity"
android:label="@string/wifi_settings"
android:theme="@style/CarSettingTheme"
- android:icon="@drawable/ic_settings_wireless">
+ android:icon="@drawable/ic_settings_wifi">
<intent-filter android:priority="1">
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
diff --git a/res/drawable/ic_settings_bluetooth_disabled.xml b/res/drawable/ic_settings_bluetooth_disabled.xml
new file mode 100644
index 0000000..20ec624
--- /dev/null
+++ b/res/drawable/ic_settings_bluetooth_disabled.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright (C) 2017 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24.0dp"
+ android:height="24.0dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M13,5.83l1.88,1.88 -1.6,1.6 1.41,1.41 3.02,-3.02L12,2h-1v5.03l2,2v-3.2zM5.41,4L4,5.41 10.59,12 5,17.59 6.41,19 11,14.41V22h1l4.29,-4.29 2.3,2.29L20,18.59 5.41,4zM13,18.17v-3.76l1.88,1.88L13,18.17z"/>
+</vector>
diff --git a/res/drawable/ic_settings_wireless.xml b/res/drawable/ic_settings_wifi.xml
similarity index 100%
rename from res/drawable/ic_settings_wireless.xml
rename to res/drawable/ic_settings_wifi.xml
diff --git a/res/drawable/ic_settings_wifi_disabled.xml b/res/drawable/ic_settings_wifi_disabled.xml
new file mode 100644
index 0000000..30550ea
--- /dev/null
+++ b/res/drawable/ic_settings_wifi_disabled.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright (C) 2017 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24.0dp"
+ android:height="24.0dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M23.64,7c-0.45,-0.34 -4.93,-4 -11.64,-4 -1.5,0 -2.89,0.19 -4.15,0.48L18.18,13.8 23.64,7zM17.04,15.22L3.27,1.44 2,2.72l2.05,2.06C1.91,5.76 0.59,6.82 0.36,7l11.63,14.49 0.01,0.01 0.01,-0.01 3.9,-4.86 3.32,3.32 1.27,-1.27 -3.46,-3.46z"/>
+</vector>
diff --git a/res/layout/action_bar_with_button.xml b/res/layout/action_bar_with_button.xml
index 8291a16..175b688 100644
--- a/res/layout/action_bar_with_button.xml
+++ b/res/layout/action_bar_with_button.xml
@@ -53,6 +53,6 @@
android:layout_gravity="center_vertical"
android:background="@null"
android:textSize="@dimen/medium_text_size"
- android:layout_marginEnd="@dimen/stream_content_keyline_1"/>
+ android:layout_marginEnd="@dimen/stream_content_keyline_1" />
</LinearLayout>
</RelativeLayout>
diff --git a/res/layout/add_wifi.xml b/res/layout/add_wifi.xml
index 5761a51..760b0de 100644
--- a/res/layout/add_wifi.xml
+++ b/res/layout/add_wifi.xml
@@ -29,7 +29,6 @@
android:layout_height="wrap_content"
android:textSize="@dimen/medium_text_size" />
<android.support.design.widget.TextInputLayout
- android:id="@+id/wifi_name_input_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.AppCompat.Light">
diff --git a/res/layout/bluetooth_details.xml b/res/layout/bluetooth_details.xml
index 99c6500..e67729d 100644
--- a/res/layout/bluetooth_details.xml
+++ b/res/layout/bluetooth_details.xml
@@ -19,15 +19,27 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
+ <android.support.design.widget.TextInputLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:theme="@style/Theme.AppCompat.Light">
+ <EditText
+ android:id="@+id/bt_name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:focusableInTouchMode="true"
+ android:textSize="@dimen/medium_text_size"
+ android:hint="@string/bluetooth_preference_paired_dialog_name_label" />
+ </android.support.design.widget.TextInputLayout>
<TextView
- android:id="@+id/bt_name"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:text="@string/bluetooth_device_advanced_profile_header_title"
android:textSize="@dimen/medium_text_size"/>
- <Button
- android:id="@+id/bt_forget"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/forget"
- />
+ <android.support.car.ui.PagedListView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/list"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"/>
</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/bluetooth_list.xml b/res/layout/bluetooth_list.xml
index 16bb47f..1e1d42f 100644
--- a/res/layout/bluetooth_list.xml
+++ b/res/layout/bluetooth_list.xml
@@ -31,7 +31,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.car.ui.PagedListView
- android:id="@android:id/list"
+ android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
diff --git a/res/layout/icon_text_line_item.xml b/res/layout/icon_text_line_item.xml
index 4a96468..0b83caf 100644
--- a/res/layout/icon_text_line_item.xml
+++ b/res/layout/icon_text_line_item.xml
@@ -24,7 +24,8 @@
android:layout_width="@dimen/tile_icon_size"
android:layout_height="@dimen/tile_icon_size"
android:layout_centerVertical="true"
- android:layout_alignParentStart="true" />
+ android:layout_alignParentStart="true"
+ android:layout_marginEnd="@dimen/car_list_item_icon_right_margin" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/res/layout/list.xml b/res/layout/list.xml
index bdd7f13..ea7d1a6 100644
--- a/res/layout/list.xml
+++ b/res/layout/list.xml
@@ -17,6 +17,6 @@
<android.support.car.ui.PagedListView
xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/list"
+ android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
\ No newline at end of file
diff --git a/res/layout/paged_list.xml b/res/layout/paged_list.xml
index c3f421e..9450761 100644
--- a/res/layout/paged_list.xml
+++ b/res/layout/paged_list.xml
@@ -20,7 +20,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.car.ui.PagedListView
- android:id="@android:id/list"
+ android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
\ No newline at end of file
diff --git a/res/layout/tile_item.xml b/res/layout/tile_item.xml
index afcf3b2..adbfddc 100644
--- a/res/layout/tile_item.xml
+++ b/res/layout/tile_item.xml
@@ -14,48 +14,53 @@
limitations under the License.
-->
-<LinearLayout
+<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dashboard_tile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
- android:minHeight="@dimen/lens_header_height"
- android:orientation="horizontal"
- android:clickable="true"
- android:focusable="true">
+ android:minHeight="@dimen/lens_header_height">
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/car_list_item_small_icon_size"
android:layout_height="@dimen/car_list_item_small_icon_size"
android:scaleType="fitCenter"
+ android:layout_alignParentStart="true"
android:layout_marginStart="@dimen/car_list_item_icon_right_margin"
android:layout_marginEnd="@dimen/car_list_item_icon_right_margin" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_1_line_item_height"
+ android:layout_toEndOf="@id/icon"
android:orientation="vertical">
- <TextView android:id="@android:id/title"
+ <TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:singleLine="true"
android:textAppearance="@style/TextAppearance.TileTitle"
android:ellipsize="marquee"
android:maxLines="1"
android:gravity="center_vertical"
android:textAlignment="center" />
- <TextView android:id="@android:id/summary"
+ <TextView android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Small"
android:textColor="?android:attr/textColorSecondary"
android:gravity="center_vertical"
android:maxLines="1"
- android:ellipsize="end"
- android:paddingEnd="@dimen/car_list_item_right_icon_margin" />
+ android:ellipsize="end" />
</LinearLayout>
-</LinearLayout>
+ <Switch
+ android:id="@+id/toggle_switch"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_alignParentEnd="true"
+ android:paddingEnd="@dimen/car_list_item_right_icon_margin"
+ android:visibility="gone"/>
+</RelativeLayout>
diff --git a/res/layout/toggle_line_item.xml b/res/layout/toggle_line_item.xml
index 56f15a0..2d29a2f 100644
--- a/res/layout/toggle_line_item.xml
+++ b/res/layout/toggle_line_item.xml
@@ -15,7 +15,10 @@
~ limitations under the License
-->
-<RelativeLayout
+<!-- The whole line item is clickable and will handle the logic change and update the switch
+ contained inside. We can't take the touch focus away from Switch due to how touch was handled in
+ that widget -->
+<com.android.car.settings.common.InterceptTouchRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@@ -40,5 +43,5 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
- android:layout_alignParentEnd="true"/>
-</RelativeLayout>
\ No newline at end of file
+ android:layout_alignParentEnd="true" />
+</com.android.car.settings.common.InterceptTouchRelativeLayout>
\ No newline at end of file
diff --git a/res/layout/wifi_list.xml b/res/layout/wifi_list.xml
index 97ac0e8..93886cc 100644
--- a/res/layout/wifi_list.xml
+++ b/res/layout/wifi_list.xml
@@ -48,7 +48,7 @@
android:layout_height="@dimen/car_divider_height"
android:background="@color/car_list_divider"/>
<android.support.car.ui.PagedListView
- android:id="@android:id/list"
+ android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fc577e1..c5d392d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -123,6 +123,19 @@
<string name="bluetooth_preference_paired_devices">Paired devices</string>
<!-- Bluetooth settings: The sub heading for available devices during and after scanning. [CHAR LIMIT=40] -->
<string name="bluetooth_preference_found_devices">Available devices</string>
+ <!-- Bluetooth settings: The sub heading for no bluetooth device has been paired with this device. [CHAR LIMIT=40] -->
+ <string name="bluetooth_preference_no_paired_devices">No paired devices</string>
+ <!-- Bluetooth settings: The sub heading for no available bluetooth devices during and after scanning. [CHAR LIMIT=40] -->
+ <string name="bluetooth_preference_no_found_devices">No available devices</string>
+ <!-- Bluetooth settings: Paired dialog title [CHAR LIMIT=40] -->
+ <string name="bluetooth_preference_paired_dialog_title">Paired device</string>
+ <!-- Bluetooth settings: Name label [CHAR LIMIT=40] -->
+ <string name="bluetooth_preference_paired_dialog_name_label">Name</string>
+ <!-- Bluetooth settings. Connection options screen. The title of the header that is above all of the profiles.
+ When a user decides what Bluetooth capabilities to use with the device. -->
+ <string name="bluetooth_device_advanced_profile_header_title">Use for</string>
+ <!-- Hint for a text field to change the name of the Bluetooth device. [CHAR LIMIT=35] -->
+ <string name="wifi_ssid_hint">Change the name of the Bluetooth device</string>
<!-- sound settings --><skip />
<!-- Sound settings screen heading -->
diff --git a/src/com/android/car/settings/CarSettingActivity.java b/src/com/android/car/settings/CarSettingActivity.java
deleted file mode 100644
index e979c92..0000000
--- a/src/com/android/car/settings/CarSettingActivity.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.car.settings;
-
-import android.content.ActivityNotFoundException;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.util.Log;
-
-import com.android.settingslib.drawer.ProfileSelectDialog;
-import com.android.settingslib.drawer.SettingsDrawerActivity;
-import com.android.settingslib.drawer.Tile;
-
-/**
- * Base activity class for car settings
- */
-public class CarSettingActivity extends SettingsDrawerActivity {
- private static final String TAG = "CarSettingActivity";
- private static final String CAR_PACKAGE = "android.car.settings.SETTINGS";
- private static final String SETTING_PKG = "com.android.car.settings";
-
- @Override
- public String getSettingAction() {
- return CAR_PACKAGE;
- }
-
- @Override
- public String getSettingPkg() {
- return SETTING_PKG;
- }
-
- public boolean openTile(Tile tile) {
- if (tile == null) {
- Intent intent = new Intent(getSettingAction()).addFlags(
- Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- return true;
- }
- try {
- ProfileSelectDialog.updateUserHandlesIfNeeded(this /* context */, tile);
- int numUserHandles = tile.userHandle.size();
- if (numUserHandles > 1) {
- ProfileSelectDialog.show(getFragmentManager(), tile);
- return false;
- } else if (numUserHandles == 1) {
- // Show menu on top level items.
- tile.intent.putExtra(EXTRA_SHOW_MENU, true);
- tile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivityAsUser(tile.intent, tile.userHandle.get(0));
- } else {
- // Show menu on top level items.
- tile.intent.putExtra(EXTRA_SHOW_MENU, true);
- tile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(tile.intent);
- }
- } catch (ActivityNotFoundException e) {
- Log.w(TAG, "Couldn't find tile " + tile.intent, e);
- }
- return true;
- }
-}
diff --git a/src/com/android/car/settings/HomepageActivity.java b/src/com/android/car/settings/HomepageActivity.java
deleted file mode 100644
index f0cb705..0000000
--- a/src/com/android/car/settings/HomepageActivity.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.car.settings;
-
-
-import android.os.Bundle;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import com.android.car.settings.common.TileRecyclerViewAdapter;
-import com.android.settingslib.drawer.CategoryKey;
-import com.android.settingslib.drawer.CategoryManager;
-
-/**
- * Homepage for settings for car.
- */
-public class HomepageActivity extends CarSettingActivity {
-
- private RecyclerView mRecyclerView;
- private TileRecyclerViewAdapter mAdapter;
- private RecyclerView.LayoutManager mLayoutManager;
-
- @Override
- protected void onCreate(Bundle savedState) {
- super.onCreate(savedState);
- setContentView(R.layout.homepage);
- mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
-
- mRecyclerView.setHasFixedSize(true);
-
- mLayoutManager = new LinearLayoutManager(this);
- mRecyclerView.setLayoutManager(mLayoutManager);
-
- mAdapter = new TileRecyclerViewAdapter(this, CategoryManager.get(this)
- .getTilesByCategory(this, CategoryKey.CATEGORY_HOMEPAGE, getSettingPkg()));
- mRecyclerView.setAdapter(mAdapter);
- }
-}
diff --git a/src/com/android/car/settings/applications/ApplicationDetailActivity.java b/src/com/android/car/settings/applications/ApplicationDetailActivity.java
index f5d6ead..ac071f0 100644
--- a/src/com/android/car/settings/applications/ApplicationDetailActivity.java
+++ b/src/com/android/car/settings/applications/ApplicationDetailActivity.java
@@ -38,7 +38,7 @@
import android.widget.ImageView;
import android.widget.TextView;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import com.android.settingslib.Utils;
@@ -67,7 +67,6 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- showMenuIcon();
setContentView(R.layout.application_details);
if (getIntent() != null && getIntent().getExtras() != null) {
mResolveInfo = getIntent().getExtras().getParcelable(APPLICATION_INFO_KEY);
diff --git a/src/com/android/car/settings/applications/ApplicationSettingsActivity.java b/src/com/android/car/settings/applications/ApplicationSettingsActivity.java
index 266da67..cc541c8 100644
--- a/src/com/android/car/settings/applications/ApplicationSettingsActivity.java
+++ b/src/com/android/car/settings/applications/ApplicationSettingsActivity.java
@@ -18,7 +18,7 @@
import android.os.Bundle;
import android.support.car.ui.PagedListView;
import android.support.v7.widget.RecyclerView;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import com.android.car.settings.common.NoDividerItemDecoration;
@@ -34,10 +34,9 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- showMenuIcon();
setContentView(R.layout.paged_list);
- mListView = (PagedListView) findViewById(android.R.id.list);
+ mListView = (PagedListView) findViewById(R.id.list);
mListView.setDefaultItemDecoration(new NoDividerItemDecoration(this));
mListView.setDarkMode();
mAdapter = new ApplicationListAdapter(this /* context */, getPackageManager());
diff --git a/src/com/android/car/settings/basePreferenceFragment.java b/src/com/android/car/settings/basePreferenceFragment.java
deleted file mode 100644
index 740b36b..0000000
--- a/src/com/android/car/settings/basePreferenceFragment.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.car.settings;
-
-import android.preference.PreferenceFragment;
-
-/**
- * Common class for preferenceFragment for car settings.
- */
-public abstract class basePreferenceFragment extends PreferenceFragment {
- abstract String getCategoryKey();
-}
diff --git a/src/com/android/car/settings/bluetooth/BluetoothDetailActivity.java b/src/com/android/car/settings/bluetooth/BluetoothDetailActivity.java
index 7318346..ff1a3dc 100644
--- a/src/com/android/car/settings/bluetooth/BluetoothDetailActivity.java
+++ b/src/com/android/car/settings/bluetooth/BluetoothDetailActivity.java
@@ -17,28 +17,56 @@
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
+import android.support.car.ui.PagedListView;
+import android.text.Editable;
+import android.text.TextWatcher;
import android.util.Log;
-import android.widget.TextView;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
+import com.android.car.settings.common.NoDividerItemDecoration;
+import com.android.car.settings.common.TypedPagedListAdapter;
+
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.bluetooth.LocalBluetoothProfile;
+import com.android.settingslib.bluetooth.MapProfile;
+import com.android.settingslib.bluetooth.PanProfile;
+import com.android.settingslib.bluetooth.PbapServerProfile;
+
+import java.util.ArrayList;
/**
* Shows details about a bluetooth device, including actions related to the device,
* e.g. forget etc. The intent should include information about the device, use that to
* render UI, e.g. show name etc.
*/
-public class BluetoothDetailActivity extends CarSettingActivity {
+public class BluetoothDetailActivity extends CarSettingActivity implements
+ BluetoothProfileLineItem.DataChangedListener {
private static final String TAG = "BluetoothDetailActivity";
public static final String BT_DEVICE_KEY = "btDeviceKey";
private BluetoothDevice mDevice;
+ private CachedBluetoothDevice mCachedDevice;
+ private PagedListView mListView;
+ private TypedPagedListAdapter mPagedListAdapter;
+ private LocalBluetoothManager mLocalManager;
+ private CachedBluetoothDeviceManager mDeviceManager;
+ private EditText mNameView;
+ private Button mOkButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- showMenuIcon();
setContentView(R.layout.bluetooth_details);
+ mListView = (PagedListView) findViewById(R.id.list);
+ mListView.setDefaultItemDecoration(new NoDividerItemDecoration(this));
+ mListView.setDarkMode();
+
if (getIntent() != null && getIntent().getExtras() != null) {
mDevice = getIntent().getExtras().getParcelable(BT_DEVICE_KEY);
}
@@ -46,23 +74,100 @@
Log.w(TAG, "No bluetooth device set.");
return;
}
- TextView nameView = (TextView) findViewById(R.id.bt_name);
- nameView.setText(mDevice.getName());
- findViewById(R.id.bt_forget).setOnClickListener(v -> {
- forget();
- finish();
- });
+
+ mLocalManager = LocalBluetoothManager.getInstance(this /* context */ , null /* listener */);
+ if (mLocalManager == null) {
+ Log.e(TAG, "Bluetooth is not supported on this device");
+ return;
+ }
+ mDeviceManager = mLocalManager.getCachedDeviceManager();
+ mCachedDevice = mDeviceManager.findDevice(mDevice);
+ if (mCachedDevice == null) {
+ mCachedDevice = mDeviceManager.addDevice(
+ mLocalManager.getBluetoothAdapter(),
+ mLocalManager.getProfileManager(),
+ mDevice);
+ }
+
+ mNameView = (EditText) findViewById(R.id.bt_name);
+ mNameView.setText(mDevice.getName());
+ setupForgetButton();
+ setupOkButton();
+
+ mPagedListAdapter = new TypedPagedListAdapter(this /* context */, getProfileLineItems());
+ mListView.setAdapter(mPagedListAdapter);
}
- private void forget() {
- int state = mDevice.getBondState();
+ @Override
+ public void setupActionBar() {
+ super.setupActionBar();
+ getActionBar().setCustomView(R.layout.action_bar_with_button);
+ getActionBar().setDisplayShowCustomEnabled(true);
+ }
- if (state == BluetoothDevice.BOND_BONDING) {
- mDevice.cancelBondProcess();
+ @Override
+ public void onDataChanged() {
+ mPagedListAdapter.notifyDataSetChanged();
+ }
+
+ private ArrayList<TypedPagedListAdapter.LineItem> getProfileLineItems() {
+ ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
+ for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
+ lineItems.add(new BluetoothProfileLineItem(
+ this /* context */, profile, mCachedDevice, this));
}
- if (state != BluetoothDevice.BOND_NONE) {
- mDevice.removeBond();
+ int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
+ // Only provide PBAP cabability if the client device has requested PBAP.
+ if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
+ PbapServerProfile psp = mLocalManager.getProfileManager().getPbapProfile();
+ lineItems.add(new BluetoothProfileLineItem(
+ this /* context */, psp, mCachedDevice, this));
}
+
+ int mapPermission = mCachedDevice.getMessagePermissionChoice();
+ if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
+ MapProfile mapProfile = mLocalManager.getProfileManager().getMapProfile();
+ lineItems.add(new BluetoothProfileLineItem(
+ this /* context */, mapProfile, mCachedDevice, this));
+ }
+ return lineItems;
+ }
+
+ private void setupForgetButton() {
+ Button fortgetButton = (Button) findViewById(R.id.action_button2);
+ fortgetButton.setVisibility(View.VISIBLE);
+ fortgetButton.setText(R.string.forget);
+ fortgetButton.setOnClickListener(v -> {
+ mCachedDevice.unpair();
+ finish();
+ });
+ }
+
+ private void setupOkButton() {
+ mOkButton = (Button) findViewById(R.id.action_button1);
+ mOkButton.setText(R.string.okay);
+ // before the text gets changed, always set it in a disabled state.
+ mOkButton.setEnabled(false);
+ mNameView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ // don't care
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ // dont' care
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mOkButton.setEnabled(!s.toString().equals(mDevice.getName()));
+ }
+ });
+ mOkButton.setOnClickListener(v -> {
+ mCachedDevice.setName(mNameView.getText().toString());
+ finish();
+ });
}
}
diff --git a/src/com/android/car/settings/bluetooth/BluetoothProfileLineItem.java b/src/com/android/car/settings/bluetooth/BluetoothProfileLineItem.java
new file mode 100644
index 0000000..d6e5592
--- /dev/null
+++ b/src/com/android/car/settings/bluetooth/BluetoothProfileLineItem.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.car.settings.bluetooth;
+
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+
+import com.android.car.settings.common.ToggleLineItem;
+
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothProfile;
+import com.android.settingslib.bluetooth.MapProfile;
+import com.android.settingslib.bluetooth.PanProfile;
+import com.android.settingslib.bluetooth.PbapServerProfile;
+
+/**
+ * Represents a line item for a Bluetooth mProfile.
+ */
+public class BluetoothProfileLineItem extends ToggleLineItem {
+ private final LocalBluetoothProfile mProfile;
+ private final CachedBluetoothDevice mCachedDevice;
+ private ToggleLineItemViewHolder mViewHolder;
+ private DataChangedListener mDataChangedListener;
+
+ public interface DataChangedListener {
+ void onDataChanged();
+ }
+
+ public BluetoothProfileLineItem(Context context, LocalBluetoothProfile profile,
+ CachedBluetoothDevice cachedBluetoothDevice, DataChangedListener listener) {
+ super(context.getText(profile.getNameResource(cachedBluetoothDevice.getDevice())));
+ mCachedDevice = cachedBluetoothDevice;
+ mProfile = profile;
+ mDataChangedListener = listener;
+ }
+
+ @Override
+ public void onClick(boolean isChecked) {
+ if (mProfile instanceof PbapServerProfile) {
+ mCachedDevice.setPhonebookPermissionChoice(isChecked
+ ? CachedBluetoothDevice.ACCESS_REJECTED : CachedBluetoothDevice.ACCESS_ALLOWED);
+ } else if (mProfile instanceof MapProfile) {
+ mCachedDevice.setMessagePermissionChoice(isChecked
+ ? CachedBluetoothDevice.ACCESS_REJECTED : CachedBluetoothDevice.ACCESS_ALLOWED);
+ } else if (isChecked) {
+ mCachedDevice.disconnect(mProfile);
+ mProfile.setPreferred(mCachedDevice.getDevice(), false);
+ } else if (mProfile.isPreferred(mCachedDevice.getDevice())) {
+ if (mProfile instanceof PanProfile) {
+ mCachedDevice.connectProfile(mProfile);
+ } else {
+ mProfile.setPreferred(mCachedDevice.getDevice(), false);
+ }
+ } else {
+ mProfile.setPreferred(mCachedDevice.getDevice(), true);
+ mCachedDevice.connectProfile(mProfile);
+ }
+ mDataChangedListener.onDataChanged();
+ }
+
+ @Override
+ public void bindViewHolder(ToggleLineItemViewHolder holder) {
+ super.bindViewHolder(holder);
+ mViewHolder = holder;
+ }
+
+ @Override
+ public CharSequence getDesc() {
+ return null;
+ }
+
+ @Override
+ public boolean isChecked() {
+ BluetoothDevice device = mCachedDevice.getDevice();
+
+ if (mProfile instanceof MapProfile) {
+ return mCachedDevice.getMessagePermissionChoice()
+ == CachedBluetoothDevice.ACCESS_ALLOWED;
+
+ } else if (mProfile instanceof PbapServerProfile) {
+ return mCachedDevice.getPhonebookPermissionChoice()
+ == CachedBluetoothDevice.ACCESS_ALLOWED;
+
+ } else if (mProfile instanceof PanProfile) {
+ return mProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED;
+
+ } else {
+ return mProfile.isPreferred(device);
+ }
+ }
+}
diff --git a/src/com/android/car/settings/bluetooth/BluetoothSettingsActivity.java b/src/com/android/car/settings/bluetooth/BluetoothSettingsActivity.java
index e0708ff..7dadec1 100644
--- a/src/com/android/car/settings/bluetooth/BluetoothSettingsActivity.java
+++ b/src/com/android/car/settings/bluetooth/BluetoothSettingsActivity.java
@@ -21,16 +21,14 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
-import android.view.View.OnClickListener;
import android.support.car.ui.PagedListView;
import android.support.v7.widget.RecyclerView;
-import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.ViewSwitcher;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import com.android.settingslib.bluetooth.BluetoothCallback;
@@ -58,8 +56,6 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bluetooth_list);
- getActionBar().setCustomView(R.layout.action_bar_with_toggle);
- getActionBar().setDisplayShowCustomEnabled(true);
((TextView) findViewById(R.id.title)).setText(R.string.bluetooth_settings);
mBluetoothSwitch = (Switch) findViewById(R.id.toggle_switch);
@@ -74,7 +70,7 @@
});
mProgressBar = (ProgressBar) findViewById(R.id.bt_search_progress);
- mDeviceListView = (PagedListView) findViewById(android.R.id.list);
+ mDeviceListView = (PagedListView) findViewById(R.id.list);
mViewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
mMessageView = (TextView) findViewById(R.id.bt_message);
@@ -94,6 +90,13 @@
}
@Override
+ public void setupActionBar() {
+ super.setupActionBar();
+ getActionBar().setCustomView(R.layout.action_bar_with_toggle);
+ getActionBar().setDisplayShowCustomEnabled(true);
+ }
+
+ @Override
public void onStart() {
super.onStart();
if (mLocalManager == null) {
diff --git a/src/com/android/car/settings/common/CarSettingActivity.java b/src/com/android/car/settings/common/CarSettingActivity.java
new file mode 100644
index 0000000..b680e43
--- /dev/null
+++ b/src/com/android/car/settings/common/CarSettingActivity.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.car.settings.common;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.view.MenuItem;
+
+
+/**
+ * Base activity class for car settings, provides a action bar with a back button that goes to
+ * previous activity.
+ */
+public class CarSettingActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setupActionBar();
+ }
+
+ /**
+ * Add logic to setup ActionBar here.
+ */
+ public void setupActionBar() {
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ /**
+ * Make home button as back button.
+ */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ onBackPressed();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/src/com/android/car/settings/common/IconTextLineItem.java b/src/com/android/car/settings/common/IconTextLineItem.java
index 9d270c6..62e8650 100644
--- a/src/com/android/car/settings/common/IconTextLineItem.java
+++ b/src/com/android/car/settings/common/IconTextLineItem.java
@@ -30,14 +30,15 @@
/**
* Contains logic for a line item represents icon and texts of a title and a description.
*/
-public abstract class IconTextLineItem extends TypedPagedListAdapter.LineItem {
- private final String mTitle;
+public abstract class IconTextLineItem
+ extends TypedPagedListAdapter.LineItem<IconTextLineItem.ViewHolder> {
+ private final CharSequence mTitle;
@DrawableRes
private final int mIconRes;
private View.OnClickListener mOnClickListener = (v) -> onClick();
- public IconTextLineItem(String title, @DrawableRes int iconRes) {
+ public IconTextLineItem(CharSequence title, @DrawableRes int iconRes) {
mTitle = title;
mIconRes = iconRes;
}
@@ -48,8 +49,7 @@
}
@Override
- public void bindViewHolder(RecyclerView.ViewHolder holder) {
- ViewHolder viewHolder = (ViewHolder) holder;
+ public void bindViewHolder(ViewHolder viewHolder) {
viewHolder.titleView.setText(mTitle);
viewHolder.iconView.setImageResource(mIconRes);
CharSequence desc = getDesc();
@@ -59,11 +59,11 @@
viewHolder.descView.setVisibility(View.VISIBLE);
viewHolder.descView.setText(desc);
}
- holder.itemView.setOnClickListener(mOnClickListener);
- holder.itemView.setEnabled(isEnabled());
+ viewHolder.itemView.setOnClickListener(mOnClickListener);
+ viewHolder.itemView.setEnabled(isEnabled());
}
- private static class ViewHolder extends RecyclerView.ViewHolder {
+ static class ViewHolder extends RecyclerView.ViewHolder {
final TextView titleView;
final TextView descView;
final ImageView iconView;
diff --git a/src/com/android/car/settings/common/IconToggleLineItem.java b/src/com/android/car/settings/common/IconToggleLineItem.java
new file mode 100644
index 0000000..ba56ab9
--- /dev/null
+++ b/src/com/android/car/settings/common/IconToggleLineItem.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.car.settings.common;
+
+import android.annotation.DrawableRes;
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.Switch;
+import android.widget.TextView;
+
+import com.android.car.settings.R;
+
+/**
+ * Contains logic for a line item represents title text, description text and a toggle widget.
+ */
+public abstract class IconToggleLineItem
+ extends TypedPagedListAdapter.LineItem<IconToggleLineItem.ViewHolder> {
+ private final Context mContext;
+ private final CharSequence mTitle;
+ protected IconUpdateListener mIconUpdateListener;
+
+ public interface IconUpdateListener {
+ void onUpdateIcon(@DrawableRes int iconRes);
+ }
+
+ private final View.OnClickListener mOnClickListener = v -> onClicked();
+
+ private final Switch.OnCheckedChangeListener mOnCheckedChangeListener =
+ (view, isChecked) -> onToggleClicked(isChecked);
+
+ public IconToggleLineItem(CharSequence title, Context context) {
+ mTitle = title;
+ mContext = context;
+ }
+
+ public int getType() {
+ return ICON_TOGGLE_TYPE;
+ }
+
+ public void bindViewHolder(ViewHolder viewHolder) {
+ viewHolder.title.setText(mTitle);
+ viewHolder.summary.setText(getDesc());
+ viewHolder.toggle.setChecked(isChecked());
+ viewHolder.onUpdateIcon(getIcon());
+ viewHolder.itemView.setOnClickListener(mOnClickListener);
+ viewHolder.toggle.setOnCheckedChangeListener(mOnCheckedChangeListener);
+ mIconUpdateListener = viewHolder;
+ }
+
+ static class ViewHolder extends RecyclerView.ViewHolder implements IconUpdateListener {
+ public final ImageView icon;
+ public final TextView title;
+ public final TextView summary;
+ public final Switch toggle;
+
+ public ViewHolder(View itemView) {
+ super(itemView);
+ icon = (ImageView) itemView.findViewById(R.id.icon);
+ title = (TextView) itemView.findViewById(R.id.title);
+ summary = (TextView) itemView.findViewById(R.id.desc);
+ toggle = (Switch) itemView.findViewById(R.id.toggle_switch);
+ toggle.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ public void onUpdateIcon(@DrawableRes int iconRes) {
+ icon.setImageResource(iconRes);
+ }
+ }
+
+ public static RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
+ View v = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.tile_item, parent, false);
+ return new ViewHolder(v);
+ }
+
+ /**
+ * Called when any part of the line is clicked.
+ * @param isChecked the state of the switch widget at the time of click.
+ */
+ public abstract void onToggleClicked(boolean isChecked);
+
+ /**
+ * called when anywhere other than the toggle on the line item got clicked.
+ */
+ public abstract void onClicked();
+
+ public abstract boolean isChecked();
+
+ public abstract @DrawableRes int getIcon();
+}
diff --git a/src/com/android/car/settings/common/InterceptTouchRelativeLayout.java b/src/com/android/car/settings/common/InterceptTouchRelativeLayout.java
new file mode 100644
index 0000000..eb8baad
--- /dev/null
+++ b/src/com/android/car/settings/common/InterceptTouchRelativeLayout.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.car.settings.common;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.widget.RelativeLayout;
+
+/**
+ * Intercepts all touch event, so they don't pass onto child views. One use case for this is to
+ * make the line item in a list view clickable and control the logic and update the sub view.
+ */
+public class InterceptTouchRelativeLayout extends RelativeLayout {
+
+ public InterceptTouchRelativeLayout(Context context) {
+ super(context);
+ }
+
+ public InterceptTouchRelativeLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public InterceptTouchRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public InterceptTouchRelativeLayout(
+ Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ /**
+ * Intercepts all touch event.
+ * @return true.
+ */
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ return true;
+ }
+}
diff --git a/src/com/android/car/settings/common/ListSettingsActivity.java b/src/com/android/car/settings/common/ListSettingsActivity.java
index 7beabe3..f0f0dfd 100644
--- a/src/com/android/car/settings/common/ListSettingsActivity.java
+++ b/src/com/android/car/settings/common/ListSettingsActivity.java
@@ -19,13 +19,12 @@
import android.os.Bundle;
import android.support.car.ui.PagedListView;
-import com.android.car.settings.CarSettingActivity;
import com.android.car.settings.R;
import java.util.ArrayList;
/**
- * Shows a list of settings
+ * Settings page that only contain a list of items.
*/
public abstract class ListSettingsActivity extends CarSettingActivity {
@@ -35,10 +34,9 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setupActionBar();
setContentView(R.layout.paged_list);
- mListView = (PagedListView) findViewById(android.R.id.list);
+ mListView = (PagedListView) findViewById(R.id.list);
mListView.setDefaultItemDecoration(new NoDividerItemDecoration(this));
mListView.setDarkMode();
mPagedListAdapter = new TypedPagedListAdapter(this /* context */, getLineItems());
@@ -49,11 +47,4 @@
* Gets a List of LineItems to show up in this activity.
*/
public abstract ArrayList<TypedPagedListAdapter.LineItem> getLineItems();
-
- /**
- * Add logic to setup ActionBar here.
- */
- public void setupActionBar() {
- showMenuIcon();
- }
}
diff --git a/src/com/android/car/settings/common/SeekbarLineItem.java b/src/com/android/car/settings/common/SeekbarLineItem.java
index a0c9cc2..294a248 100644
--- a/src/com/android/car/settings/common/SeekbarLineItem.java
+++ b/src/com/android/car/settings/common/SeekbarLineItem.java
@@ -28,7 +28,8 @@
/**
* Contains logic for a line item represents a description and a seekbar.
*/
-public abstract class SeekbarLineItem extends TypedPagedListAdapter.LineItem {
+public abstract class SeekbarLineItem
+ extends TypedPagedListAdapter.LineItem<SeekbarLineItem.ViewHolder> {
private final CharSequence mTitle;
private SeekBar.OnSeekBarChangeListener mOnSeekBarChangeListener =
@@ -60,15 +61,14 @@
}
@Override
- public void bindViewHolder(RecyclerView.ViewHolder holder) {
- ViewHolder viewHolder = (ViewHolder) holder;
+ public void bindViewHolder(ViewHolder viewHolder) {
viewHolder.titleView.setText(mTitle);
viewHolder.seekBar.setMax(getMaxSeekbarValue());
viewHolder.seekBar.setProgress(getInitialSeekbarValue());
viewHolder.seekBar.setOnSeekBarChangeListener(mOnSeekBarChangeListener);
}
- private static class ViewHolder extends RecyclerView.ViewHolder {
+ static class ViewHolder extends RecyclerView.ViewHolder {
final TextView titleView;
final SeekBar seekBar;
diff --git a/src/com/android/car/settings/common/SimpleIconLineItem.java b/src/com/android/car/settings/common/SimpleIconLineItem.java
new file mode 100644
index 0000000..9830f2e
--- /dev/null
+++ b/src/com/android/car/settings/common/SimpleIconLineItem.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.car.settings.common;
+
+import android.content.Context;
+import android.content.Intent;
+
+import android.annotation.DrawableRes;
+import android.annotation.StringRes;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.car.settings.R;
+
+/**
+ * Represents the basic line item with Icon and text.
+ */
+public class SimpleIconLineItem extends IconTextLineItem {
+ private final CharSequence mDesc;
+ private final Context mContext;
+ private final Class mActivityClass;
+
+ public SimpleIconLineItem(
+ @StringRes int title,
+ @DrawableRes int iconRes,
+ Context context,
+ CharSequence desc,
+ Class activityClass) {
+ super(context.getText(title), iconRes);
+ mDesc = desc;
+ mContext = context;
+ mActivityClass = activityClass;
+ }
+
+ @Override
+ public int getType() {
+ return SIMPLE_ICON_TEXT_TYPE;
+ }
+
+ @Override
+ public void onClick() {
+ Intent intent = new Intent(mContext, mActivityClass);
+ mContext.startActivity(intent);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public CharSequence getDesc() {
+ return mDesc;
+ }
+
+ public static RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
+ View v = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.tile_item, parent, false);
+ return new ViewHolder(v);
+ }
+}
diff --git a/src/com/android/car/settings/common/TextLineItem.java b/src/com/android/car/settings/common/TextLineItem.java
index 5d35417..95366e0 100644
--- a/src/com/android/car/settings/common/TextLineItem.java
+++ b/src/com/android/car/settings/common/TextLineItem.java
@@ -26,7 +26,7 @@
/**
* Contains logic for a line item represents text only view of a title and a description.
*/
-public abstract class TextLineItem extends TypedPagedListAdapter.LineItem {
+public abstract class TextLineItem extends TypedPagedListAdapter.LineItem<TextLineItem.ViewHolder> {
private final CharSequence mTitle;
private View.OnClickListener mOnClickListener = (v) -> onClick();
@@ -41,15 +41,14 @@
}
@Override
- public void bindViewHolder(RecyclerView.ViewHolder holder) {
- ViewHolder viewHolder = (ViewHolder) holder;
+ public void bindViewHolder(ViewHolder viewHolder) {
viewHolder.titleView.setText(mTitle);
viewHolder.descView.setText(getDesc());
- holder.itemView.setOnClickListener(mOnClickListener);
- holder.itemView.setEnabled(isEnabled());
+ viewHolder.itemView.setOnClickListener(mOnClickListener);
+ viewHolder.itemView.setEnabled(isEnabled());
}
- private static class ViewHolder extends RecyclerView.ViewHolder {
+ static class ViewHolder extends RecyclerView.ViewHolder {
final TextView titleView;
final TextView descView;
diff --git a/src/com/android/car/settings/common/TileRecyclerViewAdapter.java b/src/com/android/car/settings/common/TileRecyclerViewAdapter.java
deleted file mode 100644
index 071e0c9..0000000
--- a/src/com/android/car/settings/common/TileRecyclerViewAdapter.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.
- */
-package com.android.car.settings.common;
-
-import android.content.Context;
-import android.support.v7.widget.RecyclerView;
-import android.support.v7.widget.RecyclerView.ViewHolder;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.TextView;
-import com.android.car.settings.CarSettingActivity;
-import com.android.car.settings.R;
-import com.android.settingslib.drawer.DashboardCategory;
-import com.android.settingslib.drawer.Tile;
-
-import java.util.List;
-
-/**
- * View adapter for recycler view for tiles.
- */
-public class TileRecyclerViewAdapter extends RecyclerView.Adapter<TileRecyclerViewAdapter.TileViewHolder> {
- private final DashboardCategory mHomepageCategory;
- private final Context mContext;
-
- public static class TileViewHolder extends ViewHolder {
- public final ImageView icon;
- public final TextView title;
- public final TextView summary;
-
- public TextView mTextView;
-
- public TileViewHolder(View itemView) {
- super(itemView);
- icon = (ImageView) itemView.findViewById(R.id.icon);
- title = (TextView) itemView.findViewById(android.R.id.title);
- summary = (TextView) itemView.findViewById(android.R.id.summary);
- }
- }
-
- private View.OnClickListener mTileClickListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //TODO: get rid of setTag/getTag
- ((CarSettingActivity) mContext).openTile((Tile) v.getTag());
- }
- };
-
- public TileRecyclerViewAdapter(Context context, DashboardCategory category) {
- mContext = context;
- mHomepageCategory = category;
- }
-
- @Override
- public TileViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- View v = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.tile_item, parent, false);
- TileViewHolder vh = new TileViewHolder(v);
- return vh;
- }
-
- @Override
- public void onBindViewHolder(TileViewHolder holder, int position) {
- Tile tile = mHomepageCategory.tiles.get(position);
- holder.title.setText(tile.title);
- holder.icon.setImageIcon(tile.icon);
- holder.itemView.setTag(tile);
- holder.itemView.setOnClickListener(mTileClickListener);
- }
-
- @Override
- public int getItemCount() {
- return mHomepageCategory.tiles.size();
- }
-}
diff --git a/src/com/android/car/settings/common/ToggleLineItem.java b/src/com/android/car/settings/common/ToggleLineItem.java
index 704d703..857ee0f 100644
--- a/src/com/android/car/settings/common/ToggleLineItem.java
+++ b/src/com/android/car/settings/common/ToggleLineItem.java
@@ -17,6 +17,7 @@
package com.android.car.settings.common;
import android.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -27,7 +28,8 @@
/**
* Contains logic for a line item represents title text, description text and a toggle widget.
*/
-public abstract class ToggleLineItem extends TypedPagedListAdapter.LineItem {
+public abstract class ToggleLineItem
+ extends TypedPagedListAdapter.LineItem<ToggleLineItem.ToggleLineItemViewHolder> {
private final CharSequence mTitle;
private View.OnClickListener mOnClickListener = (v) -> {
@@ -43,20 +45,25 @@
return TOGGLE_TYPE;
}
- public void bindViewHolder(RecyclerView.ViewHolder holder) {
- ViewHolder viewHolder = (ViewHolder) holder;
+ public void bindViewHolder(ToggleLineItemViewHolder viewHolder) {
viewHolder.titleView.setText(mTitle);
- viewHolder.descView.setText(getDesc());
+ CharSequence desc = getDesc();
+ if (TextUtils.isEmpty(desc)) {
+ viewHolder.descView.setVisibility(View.GONE);
+ } else {
+ viewHolder.descView.setVisibility(View.VISIBLE);
+ viewHolder.descView.setText(desc);
+ }
viewHolder.toggle.setChecked(isChecked());
- holder.itemView.setOnClickListener(mOnClickListener);
+ viewHolder.itemView.setOnClickListener(mOnClickListener);
}
- private static class ViewHolder extends RecyclerView.ViewHolder {
+ public static class ToggleLineItemViewHolder extends RecyclerView.ViewHolder {
final TextView titleView;
final TextView descView;
- final Switch toggle;
+ public final Switch toggle;
- public ViewHolder(View view) {
+ public ToggleLineItemViewHolder(View view) {
super(view);
titleView = (TextView) view.findViewById(R.id.title);
descView = (TextView) view.findViewById(R.id.desc);
@@ -67,7 +74,7 @@
public static RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.toggle_line_item, parent, false);
- return new ViewHolder(v);
+ return new ToggleLineItemViewHolder(v);
}
/**
diff --git a/src/com/android/car/settings/common/TypedPagedListAdapter.java b/src/com/android/car/settings/common/TypedPagedListAdapter.java
index 62d2492..2d53ca2 100644
--- a/src/com/android/car/settings/common/TypedPagedListAdapter.java
+++ b/src/com/android/car/settings/common/TypedPagedListAdapter.java
@@ -51,9 +51,14 @@
return mContentList.isEmpty();
}
- public static abstract class LineItem {
+ public static abstract class LineItem<VH extends ViewHolder> {
@Retention(SOURCE)
- @IntDef({TEXT_TYPE, TOGGLE_TYPE, ICON_TEXT_TYPE})
+ @IntDef({TEXT_TYPE,
+ TOGGLE_TYPE,
+ ICON_TEXT_TYPE,
+ SEEKBAR_TYPE,
+ ICON_TOGGLE_TYPE,
+ SIMPLE_ICON_TEXT_TYPE})
public @interface LineItemType {}
// with one title and one description
@@ -68,10 +73,16 @@
// with one tile and one seekbar.
static final int SEEKBAR_TYPE = 4;
+ // with one icon, title, description and a toggle.
+ static final int ICON_TOGGLE_TYPE = 5;
+
+ // similar to ICON_TEXT_TYPE, but with a different layout.
+ static final int SIMPLE_ICON_TEXT_TYPE = 6;
+
@LineItemType
abstract int getType();
- abstract void bindViewHolder(ViewHolder holder);
+ abstract void bindViewHolder(VH holder);
public abstract CharSequence getDesc();
}
@@ -87,6 +98,10 @@
return IconTextLineItem.createViewHolder(parent);
case LineItem.SEEKBAR_TYPE:
return SeekbarLineItem.createViewHolder(parent);
+ case LineItem.ICON_TOGGLE_TYPE:
+ return IconToggleLineItem.createViewHolder(parent);
+ case LineItem.SIMPLE_ICON_TEXT_TYPE:
+ return SimpleIconLineItem.createViewHolder(parent);
default:
throw new IllegalStateException("ViewType not supported: " + viewType);
}
diff --git a/src/com/android/car/settings/core/CarPreferenceController.java b/src/com/android/car/settings/core/CarPreferenceController.java
deleted file mode 100644
index 7aa603a..0000000
--- a/src/com/android/car/settings/core/CarPreferenceController.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-package com.android.car.settings.core;
-
-
-import android.content.Context;
-import android.support.v7.preference.Preference;
-import com.android.settingslib.core.AbstractPreferenceController;
-
-
-public abstract class CarPreferenceController extends AbstractPreferenceController
- implements Preference.OnPreferenceChangeListener {
-
- public CarPreferenceController(Context context) {
- super(context);
- }
-}
diff --git a/src/com/android/car/settings/core/CarSettings.java b/src/com/android/car/settings/core/CarSettings.java
deleted file mode 100644
index 37e751d..0000000
--- a/src/com/android/car/settings/core/CarSettings.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.car.settings.core;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.v14.preference.PreferenceFragment;
-import android.support.v7.preference.Preference;
-import android.util.Log;
-import com.android.car.settings.R;
-
-import java.util.List;
-
-
-/**
- * Settings fragments for car related settings.
- */
-public abstract class CarSettings extends PreferenceFragment {
- private static final String TAG = "CarSettings";
-
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- List<CarPreferenceController> controllers = getControllers(getContext());
- for (CarPreferenceController controller : controllers) {
- bindController(controller);
- }
- }
-
- abstract public List<CarPreferenceController> getControllers(Context context);
-
- private void bindController(@NonNull CarPreferenceController controller) {
- Preference preference = findPreference(controller.getPreferenceKey());
- if (preference == null) {
- Log.w(TAG, String.format(
- "Preference[%s] does not exist.", controller.getPreferenceKey()));
- return;
- }
- preference.setOnPreferenceChangeListener(controller);
- controller.updateState(preference);
- }
-}
diff --git a/src/com/android/car/settings/datetime/DatePickerActivity.java b/src/com/android/car/settings/datetime/DatePickerActivity.java
index a3b07fc..33b676e 100644
--- a/src/com/android/car/settings/datetime/DatePickerActivity.java
+++ b/src/com/android/car/settings/datetime/DatePickerActivity.java
@@ -21,7 +21,7 @@
import android.os.Bundle;
import android.widget.DatePicker;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import java.util.Calendar;
@@ -37,7 +37,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- showMenuIcon();
+
setContentView(R.layout.date_picker);
mDatePicker = (DatePicker) findViewById(R.id.date_picker);
diff --git a/src/com/android/car/settings/datetime/TimePickerActivity.java b/src/com/android/car/settings/datetime/TimePickerActivity.java
index ad8fa0f..2e831be 100644
--- a/src/com/android/car/settings/datetime/TimePickerActivity.java
+++ b/src/com/android/car/settings/datetime/TimePickerActivity.java
@@ -22,7 +22,7 @@
import android.os.Bundle;
import android.widget.TimePicker;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import java.util.Calendar;
@@ -38,7 +38,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- showMenuIcon();
+
setContentView(R.layout.time_picker);
mTimePicker = (TimePicker) findViewById(R.id.time_picker);
diff --git a/src/com/android/car/settings/datetime/TimeZonePickerActivity.java b/src/com/android/car/settings/datetime/TimeZonePickerActivity.java
index a8a10d7..628ed6f 100644
--- a/src/com/android/car/settings/datetime/TimeZonePickerActivity.java
+++ b/src/com/android/car/settings/datetime/TimeZonePickerActivity.java
@@ -20,7 +20,7 @@
import android.os.Bundle;
import android.support.car.ui.PagedListView;
import android.support.v7.widget.RecyclerView;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import com.android.car.settings.common.NoDividerItemDecoration;
@@ -33,7 +33,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- showMenuIcon();
+
setContentView(R.layout.list);
PagedListView listView = (PagedListView) findViewById(android.R.id.list);
diff --git a/src/com/android/car/settings/display/AutoBrightnessLineItem.java b/src/com/android/car/settings/display/AutoBrightnessLineItem.java
index b490cfd..f025a64 100644
--- a/src/com/android/car/settings/display/AutoBrightnessLineItem.java
+++ b/src/com/android/car/settings/display/AutoBrightnessLineItem.java
@@ -58,7 +58,7 @@
}
@Override
- public void bindViewHolder(RecyclerView.ViewHolder holder) {
+ public void bindViewHolder(ToggleLineItemViewHolder holder) {
super.bindViewHolder(holder);
holder.itemView.setEnabled(isEnabled());
}
diff --git a/src/com/android/car/settings/home/BluetoothLineItem.java b/src/com/android/car/settings/home/BluetoothLineItem.java
new file mode 100644
index 0000000..9de21b9
--- /dev/null
+++ b/src/com/android/car/settings/home/BluetoothLineItem.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.car.settings.home;
+
+import android.annotation.DrawableRes;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothManager;
+import android.content.Context;
+import android.content.Intent;
+
+import com.android.car.settings.R;
+import com.android.car.settings.bluetooth.BluetoothSettingsActivity;
+import com.android.car.settings.common.IconToggleLineItem;
+
+
+/**
+ * Represents the Bluetooth line item on settings home page.
+ */
+public class BluetoothLineItem extends IconToggleLineItem {
+ private final Context mContext;
+ private BluetoothAdapter mBluetoothAdapter;
+
+ public BluetoothLineItem(Context context) {
+ super(context.getText(R.string.bluetooth_settings), context);
+ mContext = context;
+ mBluetoothAdapter = ((BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE))
+ .getAdapter();
+ }
+
+ @Override
+ public void onToggleClicked(boolean isChecked) {
+ if (isChecked) {
+ mBluetoothAdapter.enable();
+ } else {
+ mBluetoothAdapter.disable();
+ }
+ }
+
+ @Override
+ public void onClicked() {
+ Intent intent = new Intent(mContext, BluetoothSettingsActivity.class);
+ mContext.startActivity(intent);
+ }
+
+ @Override
+ public CharSequence getDesc() {
+ return mContext.getText(R.string.bluetooth_settings_summary);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mBluetoothAdapter.isEnabled();
+ }
+
+ @Override
+ public @DrawableRes int getIcon() {
+ return getIconRes(mBluetoothAdapter.isEnabled());
+ }
+
+ public void onBluetoothStateChanged(boolean enabled) {
+ if (mIconUpdateListener == null) {
+ return;
+ }
+ mIconUpdateListener.onUpdateIcon(getIconRes(enabled));
+ }
+
+ private @DrawableRes int getIconRes(boolean enabled) {
+ return enabled
+ ? R.drawable.ic_settings_bluetooth : R.drawable.ic_settings_bluetooth_disabled;
+ }
+}
diff --git a/src/com/android/car/settings/home/HomepageActivity.java b/src/com/android/car/settings/home/HomepageActivity.java
new file mode 100644
index 0000000..ce59b73
--- /dev/null
+++ b/src/com/android/car/settings/home/HomepageActivity.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.car.settings.home;
+
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+
+import com.android.car.settings.R;
+import com.android.car.settings.applications.ApplicationSettingsActivity;
+import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.common.SimpleIconLineItem;
+import com.android.car.settings.common.TypedPagedListAdapter;
+import com.android.car.settings.datetime.DatetimeSettingsActivity;
+import com.android.car.settings.display.DisplaySettingsActivity;
+import com.android.car.settings.sound.SoundSettingsActivity;
+import com.android.car.settings.system.SystemSettingsActivity;
+import com.android.car.settings.wifi.CarWifiManager;
+
+import java.util.ArrayList;
+
+/**
+ * Homepage for settings for car.
+ */
+public class HomepageActivity extends ListSettingsActivity implements CarWifiManager.Listener {
+ private CarWifiManager mCarWifiManager;
+ private WifiLineItem mWifiLineItem;
+ private BluetoothLineItem mBluetoothLineItem;
+
+ private final BroadcastReceiver mBtStateReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+
+ if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
+ int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
+ BluetoothAdapter.ERROR);
+ switch (state) {
+ case BluetoothAdapter.STATE_TURNING_OFF:
+ // TODO show a different status icon?
+ case BluetoothAdapter.STATE_OFF:
+ mBluetoothLineItem.onBluetoothStateChanged(false);
+ break;
+ default:
+ mBluetoothLineItem.onBluetoothStateChanged(true);
+ }
+ }
+ }
+ };
+ private final IntentFilter mBtStateChangeFilter =
+ new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ mCarWifiManager = new CarWifiManager(this /* context */ , this /* listener */);
+ mWifiLineItem = new WifiLineItem(this, mCarWifiManager);
+ mBluetoothLineItem = new BluetoothLineItem(this);
+
+ // Call super after the wifiLineItem and BluetoothLineItem are setup, because
+ // those are needed in super.onCreate().
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onAccessPointsChanged() {
+ // don't care
+ }
+
+ @Override
+ public void onWifiStateChanged(int state) {
+ mWifiLineItem.onWifiStateChanged(state);
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ mCarWifiManager.start();
+ registerReceiver(mBtStateReceiver, mBtStateChangeFilter);
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ mCarWifiManager.stop();
+ unregisterReceiver(mBtStateReceiver);
+ }
+
+ @Override
+ public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
+ ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
+ lineItems.add(new SimpleIconLineItem(
+ R.string.display_settings,
+ R.drawable.ic_settings_display,
+ this,
+ null,
+ DatetimeSettingsActivity.class));
+ lineItems.add(new SimpleIconLineItem(
+ R.string.sound_settings,
+ R.drawable.ic_settings_sound,
+ this,
+ null,
+ SoundSettingsActivity.class));
+ lineItems.add(mWifiLineItem);
+ lineItems.add(mBluetoothLineItem);
+ lineItems.add(new SimpleIconLineItem(
+ R.string.applications_settings,
+ R.drawable.ic_settings_applications,
+ this,
+ null,
+ ApplicationSettingsActivity.class));
+ lineItems.add(new SimpleIconLineItem(
+ R.string.display_settings,
+ R.drawable.ic_settings_display,
+ this,
+ null,
+ DisplaySettingsActivity.class));
+ lineItems.add(new SimpleIconLineItem(
+ R.string.system_setting_title,
+ R.drawable.ic_settings_about,
+ this,
+ null,
+ SystemSettingsActivity.class));
+ return lineItems;
+ }
+
+ @Override
+ public void setupActionBar() {
+ getActionBar().hide();
+ }
+}
diff --git a/src/com/android/car/settings/home/WifiLineItem.java b/src/com/android/car/settings/home/WifiLineItem.java
new file mode 100644
index 0000000..39c2616
--- /dev/null
+++ b/src/com/android/car/settings/home/WifiLineItem.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.car.settings.home;
+
+import android.annotation.DrawableRes;
+import android.annotation.StringRes;
+import android.content.Context;
+import android.content.Intent;
+import android.net.wifi.WifiManager;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.IconToggleLineItem;
+import com.android.car.settings.wifi.CarWifiManager;
+import com.android.car.settings.wifi.WifiSettingsActivity;
+
+
+/**
+ * Represents the wifi line item on settings home page.
+ */
+public class WifiLineItem extends IconToggleLineItem {
+ private final Context mContext;
+ private final CarWifiManager mCarWifiManager;
+
+ public WifiLineItem(Context context, CarWifiManager carWifiManager) {
+ super(context.getText(R.string.wifi_settings), context);
+ mContext = context;
+ mCarWifiManager = carWifiManager;
+ }
+
+ @Override
+ public void onToggleClicked(boolean isChecked) {
+ mCarWifiManager.setWifiEnabled(isChecked);
+ }
+
+ @Override
+ public void onClicked() {
+ Intent intent = new Intent(mContext, WifiSettingsActivity.class);
+ mContext.startActivity(intent);
+ }
+
+ @Override
+ public CharSequence getDesc() {
+ return mContext.getText(R.string.wifi_settings_summary);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mCarWifiManager.isWifiEnabled();
+ }
+
+ @Override
+ public @DrawableRes int getIcon() {
+ return getIconRes(mCarWifiManager.getWifiState());
+ }
+
+ public void onWifiStateChanged(int state) {
+ if (mIconUpdateListener == null) {
+ return;
+ }
+ mIconUpdateListener.onUpdateIcon(getIconRes(state));
+ }
+
+ private @DrawableRes int getIconRes(int state) {
+ switch (state) {
+ case WifiManager.WIFI_STATE_ENABLING:
+ //TODO show gray out?
+ case WifiManager.WIFI_STATE_DISABLED:
+ return R.drawable.ic_settings_wifi_disabled;
+ default:
+ return R.drawable.ic_settings_wifi;
+ }
+ }
+}
diff --git a/src/com/android/car/settings/sound/SoundSettingsActivity.java b/src/com/android/car/settings/sound/SoundSettingsActivity.java
index 5e13185..07c9d97 100644
--- a/src/com/android/car/settings/sound/SoundSettingsActivity.java
+++ b/src/com/android/car/settings/sound/SoundSettingsActivity.java
@@ -23,7 +23,7 @@
import android.os.IBinder;
import android.view.View;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
/**
@@ -39,7 +39,6 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- showMenuIcon();
setContentView(R.layout.volume_list);
View mediaVolumeControllerView = findViewById(
diff --git a/src/com/android/car/settings/wifi/AddWifiActivity.java b/src/com/android/car/settings/wifi/AddWifiActivity.java
index a193bf4..d36400a 100644
--- a/src/com/android/car/settings/wifi/AddWifiActivity.java
+++ b/src/com/android/car/settings/wifi/AddWifiActivity.java
@@ -24,11 +24,10 @@
import android.widget.Toast;
import android.widget.ViewSwitcher;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import com.android.settingslib.wifi.AccessPoint;
-import java.util.HashSet;
import java.util.regex.Pattern;
/**
@@ -65,7 +64,7 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWifiManager = (WifiManager) getSystemService(WifiManager.class);
- showMenuIcon();
+
setContentView(R.layout.add_wifi);
mSSidViewSwitcher = (ViewSwitcher) findViewById(R.id.wifi_name);
mWifiNameDisplay = (TextView) findViewById(R.id.wifi_name_display);
diff --git a/src/com/android/car/settings/wifi/CarWifiManager.java b/src/com/android/car/settings/wifi/CarWifiManager.java
index 559ef13..32db2c0 100644
--- a/src/com/android/car/settings/wifi/CarWifiManager.java
+++ b/src/com/android/car/settings/wifi/CarWifiManager.java
@@ -40,7 +40,7 @@
private WifiTracker mWifiTracker;
private final HandlerThread mBgThread;
private WifiManager mWifiManager;
- interface Listener {
+ public interface Listener {
/**
* Something about wifi setting changed.
*/
@@ -112,6 +112,10 @@
return mWifiManager.isWifiEnabled();
}
+ public int getWifiState() {
+ return mWifiManager.getWifiState();
+ }
+
public boolean setWifiEnabled(boolean enabled) {
return mWifiManager.setWifiEnabled(enabled);
}
diff --git a/src/com/android/car/settings/wifi/WifiDetailActivity.java b/src/com/android/car/settings/wifi/WifiDetailActivity.java
index fbd2a21..59b312b 100644
--- a/src/com/android/car/settings/wifi/WifiDetailActivity.java
+++ b/src/com/android/car/settings/wifi/WifiDetailActivity.java
@@ -30,7 +30,6 @@
import com.android.car.settings.common.TypedPagedListAdapter;
import com.android.settingslib.wifi.AccessPoint;
-import com.android.car.settings.CarSettingActivity;
import com.android.car.settings.R;
import java.util.ArrayList;
@@ -65,9 +64,9 @@
@Override
public void setupActionBar() {
+ super.setupActionBar();
getActionBar().setCustomView(R.layout.action_bar_with_button);
getActionBar().setDisplayShowCustomEnabled(true);
- showMenuIcon();
}
@Override
diff --git a/src/com/android/car/settings/wifi/WifiSettingsActivity.java b/src/com/android/car/settings/wifi/WifiSettingsActivity.java
index 123ec3e..9ca6b02 100644
--- a/src/com/android/car/settings/wifi/WifiSettingsActivity.java
+++ b/src/com/android/car/settings/wifi/WifiSettingsActivity.java
@@ -23,8 +23,6 @@
import android.support.car.ui.PagedListView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Switch;
@@ -33,7 +31,7 @@
import android.annotation.StringRes;
-import com.android.car.settings.CarSettingActivity;
+import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
import com.android.settingslib.wifi.AccessPoint;
@@ -60,11 +58,10 @@
super.onCreate(savedInstanceState);
mCarWifiManager = new CarWifiManager(this /* context */ , this /* listener */);
setContentView(R.layout.wifi_list);
- getActionBar().setCustomView(R.layout.action_bar_with_toggle);
- getActionBar().setDisplayShowCustomEnabled(true);
- ((TextView) findViewById(R.id.title)).setText(R.string.wifi_settings);
+
+ ((TextView) findViewById(R.id.action_bar_title)).setText(R.string.wifi_settings);
mProgressBar = (ProgressBar) findViewById(R.id.wifi_search_progress);
- mListView = (PagedListView) findViewById(android.R.id.list);
+ mListView = (PagedListView) findViewById(R.id.list);
mMessageView = (TextView) findViewById(R.id.message);
mViewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
mAddWifiTextView = (TextView) findViewById(R.id.add_wifi);
@@ -90,6 +87,13 @@
}
@Override
+ public void setupActionBar() {
+ getActionBar().setCustomView(R.layout.action_bar_with_toggle);
+ getActionBar().setDisplayShowCustomEnabled(true);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ @Override
public void onStart() {
super.onStart();
mCarWifiManager.start();
diff --git a/tests/robotests/src/com/android/car/settings/CarSettingActivityTest.java b/tests/robotests/src/com/android/car/settings/CarSettingActivityTest.java
deleted file mode 100644
index 44f3b4d..0000000
--- a/tests/robotests/src/com/android/car/settings/CarSettingActivityTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.car.settings;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.google.common.truth.Truth.assertThat;
-
-@RunWith(CarSettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class CarSettingActivityTest {
-
- private CarSettingActivity mActivity;
-
- @Test
- public void testConstant() {
- mActivity = new CarSettingActivity();
- assertThat(mActivity.getSettingAction()).isEqualTo("android.car.settings.SETTINGS");
- assertThat(mActivity.getSettingPkg()).isEqualTo("com.android.car.settings");
- }
-}