add system settings

Test: manually verified
Change-Id: Ie9c9b4ccea92a4601e4e0b9ff7f4bf75f8fef89a
diff --git a/src/com/android/car/settings/common/IconTextLineItem.java b/src/com/android/car/settings/common/IconTextLineItem.java
new file mode 100644
index 0000000..9d270c6
--- /dev/null
+++ b/src/com/android/car/settings/common/IconTextLineItem.java
@@ -0,0 +1,88 @@
+/*
+ * 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.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
+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.R;
+
+/**
+ * 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;
+    @DrawableRes
+    private final int mIconRes;
+
+    private View.OnClickListener mOnClickListener = (v) -> onClick();
+
+    public IconTextLineItem(String title, @DrawableRes int iconRes) {
+        mTitle = title;
+        mIconRes = iconRes;
+    }
+
+    @Override
+    public int getType() {
+        return ICON_TEXT_TYPE;
+    }
+
+    @Override
+    public void bindViewHolder(RecyclerView.ViewHolder holder) {
+        ViewHolder viewHolder = (ViewHolder) holder;
+        viewHolder.titleView.setText(mTitle);
+        viewHolder.iconView.setImageResource(mIconRes);
+        CharSequence desc = getDesc();
+        if (TextUtils.isEmpty(desc)) {
+            viewHolder.descView.setVisibility(View.GONE);
+        } else {
+            viewHolder.descView.setVisibility(View.VISIBLE);
+            viewHolder.descView.setText(desc);
+        }
+        holder.itemView.setOnClickListener(mOnClickListener);
+        holder.itemView.setEnabled(isEnabled());
+    }
+
+    private static class ViewHolder extends RecyclerView.ViewHolder {
+        final TextView titleView;
+        final TextView descView;
+        final ImageView iconView;
+
+        public ViewHolder(View view) {
+            super(view);
+            iconView = (ImageView) view.findViewById(R.id.icon);
+            titleView = (TextView) view.findViewById(R.id.title);
+            descView = (TextView) view.findViewById(R.id.desc);
+        }
+    }
+
+    public static RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
+        View v = LayoutInflater.from(parent.getContext())
+                .inflate(R.layout.icon_text_line_item, parent, false);
+        return new ViewHolder(v);
+    }
+
+    public abstract void onClick();
+
+    public abstract boolean isEnabled();
+}
diff --git a/src/com/android/car/settings/common/ListSettingsActivity.java b/src/com/android/car/settings/common/ListSettingsActivity.java
new file mode 100644
index 0000000..dea5cb8
--- /dev/null
+++ b/src/com/android/car/settings/common/ListSettingsActivity.java
@@ -0,0 +1,52 @@
+/*
+ * 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.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
+ */
+public abstract class ListSettingsActivity extends CarSettingActivity {
+
+    private PagedListView mListView;
+    protected TypedPagedListAdapter mPagedListAdapter;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        showMenuIcon();
+        setContentView(R.layout.paged_list);
+
+        mListView = (PagedListView) findViewById(android.R.id.list);
+        mListView.setDefaultItemDecoration(new NoDividerItemDecoration(this));
+        mListView.setDarkMode();
+        mPagedListAdapter = new TypedPagedListAdapter(this /* context */, getLineItems());
+        mListView.setAdapter(mPagedListAdapter);
+    }
+
+    /**
+     * Gets a List of LineItems to show up in this activity.
+     */
+    public abstract ArrayList<TypedPagedListAdapter.LineItem> getLineItems();
+}
diff --git a/src/com/android/car/settings/common/SimpleTextLineItem.java b/src/com/android/car/settings/common/SimpleTextLineItem.java
new file mode 100644
index 0000000..d026410
--- /dev/null
+++ b/src/com/android/car/settings/common/SimpleTextLineItem.java
@@ -0,0 +1,47 @@
+/*
+ * 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 com.android.car.settings.R;
+
+/**
+ * A LineItem that displays a title and description. Not clickable.
+ */
+public class SimpleTextLineItem extends TextLineItem {
+
+    private final CharSequence mDesc;
+
+    public SimpleTextLineItem(CharSequence title, CharSequence desc) {
+        super(title);
+        mDesc = desc;
+    }
+
+    @Override
+    public CharSequence getDesc() {
+        return mDesc;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return false;
+    }
+
+    @Override
+    public void onClick() {
+        // no-op
+    }
+}
diff --git a/src/com/android/car/settings/common/TextLineItem.java b/src/com/android/car/settings/common/TextLineItem.java
index 642fa93..7a77b9f 100644
--- a/src/com/android/car/settings/common/TextLineItem.java
+++ b/src/com/android/car/settings/common/TextLineItem.java
@@ -27,13 +27,13 @@
  * Contains logic for a line item represents text only view of a title and a description.
  */
 public abstract class TextLineItem extends TypedPagedListAdapter.LineItem {
-    private final String mTitle;
+    private final CharSequence mTitle;
 
     private View.OnClickListener mOnClickListener = (v) -> {
             TextLineItem.this.onClick();
         };
 
-    public TextLineItem(String title) {
+    public TextLineItem(CharSequence title) {
         mTitle = title;
     }
 
diff --git a/src/com/android/car/settings/common/TypedPagedListAdapter.java b/src/com/android/car/settings/common/TypedPagedListAdapter.java
index f6de687..706e955 100644
--- a/src/com/android/car/settings/common/TypedPagedListAdapter.java
+++ b/src/com/android/car/settings/common/TypedPagedListAdapter.java
@@ -53,7 +53,7 @@
 
     public static abstract class LineItem {
         @Retention(SOURCE)
-        @IntDef({TEXT_TYPE, TOGGLE_TYPE})
+        @IntDef({TEXT_TYPE, TOGGLE_TYPE, ICON_TEXT_TYPE})
         public @interface LineItemType {}
 
         // with one title and one description
@@ -62,6 +62,9 @@
         // with one tile, one description, and a toggle on the right.
         static final int TOGGLE_TYPE = 2;
 
+        // with one icon, one tile and one description.
+        static final int ICON_TEXT_TYPE = 3;
+
         @LineItemType
         abstract int getType();
 
@@ -77,6 +80,8 @@
                 return TextLineItem.createViewHolder(parent);
             case LineItem.TOGGLE_TYPE:
                 return ToggleLineItem.createViewHolder(parent);
+            case LineItem.ICON_TEXT_TYPE:
+                return IconTextLineItem.createViewHolder(parent);
             default:
                 throw new IllegalStateException("ViewType not supported: " + viewType);
         }
diff --git a/src/com/android/car/settings/datetime/DatetimeSettingsActivity.java b/src/com/android/car/settings/datetime/DatetimeSettingsActivity.java
index 052e596..69143e6 100644
--- a/src/com/android/car/settings/datetime/DatetimeSettingsActivity.java
+++ b/src/com/android/car/settings/datetime/DatetimeSettingsActivity.java
@@ -19,24 +19,18 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.os.Bundle;
 import android.provider.Settings;
 
-import android.support.car.ui.PagedListView;
-import android.support.v7.widget.RecyclerView;
-import com.android.car.settings.CarSettingActivity;
 import com.android.car.settings.R;
-import com.android.car.settings.common.NoDividerItemDecoration;
+import com.android.car.settings.common.ListSettingsActivity;
 import com.android.car.settings.common.TypedPagedListAdapter;
-import com.android.settingslib.datetime.ZoneGetter;
 
 import java.util.ArrayList;
-import java.util.Calendar;
 
 /**
  * Configures date time
  */
-public class DatetimeSettingsActivity extends CarSettingActivity {
+public class DatetimeSettingsActivity extends ListSettingsActivity {
     private static final String TAG = "DatetimeSettingsActivity";
 
     private static final IntentFilter TIME_CHANGED_FILTER =
@@ -48,34 +42,22 @@
     private final TimeChangedBroadCastReceiver mTimeChangedBroadCastReceiver =
             new TimeChangedBroadCastReceiver();
 
-    private PagedListView mListView;
-    private TypedPagedListAdapter mPagedListAdapter;
-    private final ArrayList<TypedPagedListAdapter.LineItem> mLineItems = new ArrayList<>();
-
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        showMenuIcon();
-        setContentView(R.layout.paged_list);
-
-        mLineItems.add(new DateTimeToggleLineItem(this,
+    public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
+        ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
+        lineItems.add(new DateTimeToggleLineItem(this,
                 getString(R.string.date_time_auto),
                 getString(R.string.date_time_auto_summary),
                 Settings.Global.AUTO_TIME));
-        mLineItems.add(new DateTimeToggleLineItem(this,
+        lineItems.add(new DateTimeToggleLineItem(this,
                 getString(R.string.zone_auto),
                 getString(R.string.zone_auto_summary),
                 Settings.Global.AUTO_TIME_ZONE));
-        mLineItems.add(new SetDateLineItem(this));
-        mLineItems.add(new SetTimeLineItem(this));
-        mLineItems.add(new SetTimeZoneLineItem(this));
-        mLineItems.add(new TimeFormatToggleLineItem(this));
-
-        mListView = (PagedListView) findViewById(android.R.id.list);
-        mListView.setDefaultItemDecoration(new NoDividerItemDecoration(this));
-        mListView.setDarkMode();
-        mPagedListAdapter = new TypedPagedListAdapter(this /* context */, mLineItems);
-        mListView.setAdapter(mPagedListAdapter);
+        lineItems.add(new SetDateLineItem(this));
+        lineItems.add(new SetTimeLineItem(this));
+        lineItems.add(new SetTimeZoneLineItem(this));
+        lineItems.add(new TimeFormatToggleLineItem(this));
+        return lineItems;
     }
 
     @Override
diff --git a/src/com/android/car/settings/system/AboutSettingsActivity.java b/src/com/android/car/settings/system/AboutSettingsActivity.java
new file mode 100644
index 0000000..a2ea9ba
--- /dev/null
+++ b/src/com/android/car/settings/system/AboutSettingsActivity.java
@@ -0,0 +1,50 @@
+/*
+ * 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.system;
+
+import android.os.Build;
+
+import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.common.SimpleTextLineItem;
+import com.android.car.settings.common.TypedPagedListAdapter;
+import com.android.car.settings.R;
+import com.android.settingslib.DeviceInfoUtils;
+
+import java.util.ArrayList;
+
+/**
+ * Shows basic info about the system and provide some actions like update, reset etc.
+ */
+public class AboutSettingsActivity extends ListSettingsActivity {
+
+    @Override
+    public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
+        ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
+        lineItems.add(new SimpleTextLineItem(
+                getText(R.string.model_info), Build.MODEL + DeviceInfoUtils.getMsvSuffix()));
+        lineItems.add(new SimpleTextLineItem(
+                getText(R.string.firmware_version),
+                getString(R.string.about_summary, Build.VERSION.RELEASE)));
+        lineItems.add(new SimpleTextLineItem(
+                getText(R.string.security_patch), DeviceInfoUtils.getSecurityPatch()));
+        lineItems.add(new SimpleTextLineItem(
+                getText(R.string.kernel_version), DeviceInfoUtils.getFormattedKernelVersion()));
+        lineItems.add(new SimpleTextLineItem(
+                getText(R.string.build_number), Build.DISPLAY));
+        return lineItems;
+    }
+}
diff --git a/src/com/android/car/settings/system/AboutSystemLineItem.java b/src/com/android/car/settings/system/AboutSystemLineItem.java
new file mode 100644
index 0000000..0334540
--- /dev/null
+++ b/src/com/android/car/settings/system/AboutSystemLineItem.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.system;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.IconTextLineItem;
+
+
+/**
+ * A LineItem that displays info about system.
+ */
+class AboutSystemLineItem extends IconTextLineItem {
+
+    private final Context mContext;
+
+    public AboutSystemLineItem(Context context) {
+        super(context.getString(R.string.about_settings), R.drawable.ic_settings_about);
+        mContext = context;
+    }
+
+    @Override
+    public CharSequence getDesc() {
+        return mContext.getString(R.string.about_summary, Build.VERSION.RELEASE);
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+
+    @Override
+    public void onClick() {
+        Intent intent = new Intent(mContext, AboutSettingsActivity.class);
+        mContext.startActivity(intent);
+    }
+}
diff --git a/src/com/android/car/settings/system/LegalInfoLineItem.java b/src/com/android/car/settings/system/LegalInfoLineItem.java
new file mode 100644
index 0000000..663d16b
--- /dev/null
+++ b/src/com/android/car/settings/system/LegalInfoLineItem.java
@@ -0,0 +1,51 @@
+/*
+ * 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.system;
+
+import android.content.Context;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.IconTextLineItem;
+
+
+/**
+ * A LineItem that displays info about legal document.
+ */
+class LegalInfoLineItem extends IconTextLineItem {
+
+    private final Context mContext;
+
+    public LegalInfoLineItem(Context context) {
+        super(context.getString(R.string.legal_information), R.drawable.ic_settings_about);
+        mContext = context;
+    }
+
+    @Override
+    public CharSequence getDesc() {
+        return null;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+
+    @Override
+    public void onClick() {
+        // TODO: link to a legal info page.
+    }
+}
diff --git a/src/com/android/car/settings/system/SystemSettingsActivity.java b/src/com/android/car/settings/system/SystemSettingsActivity.java
new file mode 100644
index 0000000..37d1614
--- /dev/null
+++ b/src/com/android/car/settings/system/SystemSettingsActivity.java
@@ -0,0 +1,38 @@
+/*
+ * 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.system;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.common.TypedPagedListAdapter;
+
+import java.util.ArrayList;
+
+/**
+ * Shows basic info about the system and provide some actions like update, reset etc.
+ */
+public class SystemSettingsActivity extends ListSettingsActivity {
+
+    @Override
+    public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
+        ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
+        lineItems.add(new SystemUpdatesLineItem(this));
+        lineItems.add(new AboutSystemLineItem(this));
+        lineItems.add(new LegalInfoLineItem(this));
+        return lineItems;
+    }
+}
diff --git a/src/com/android/car/settings/system/SystemUpdatesLineItem.java b/src/com/android/car/settings/system/SystemUpdatesLineItem.java
new file mode 100644
index 0000000..034b9df
--- /dev/null
+++ b/src/com/android/car/settings/system/SystemUpdatesLineItem.java
@@ -0,0 +1,53 @@
+/*
+ * 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.system;
+
+import android.content.Context;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.IconTextLineItem;
+
+
+/**
+ * A LineItem that links to system update.
+ */
+class SystemUpdatesLineItem extends IconTextLineItem {
+    private static final String TAG = "SystemUpdatesLineItem";
+
+    private final Context mContext;
+
+    public SystemUpdatesLineItem(Context context) {
+        super(context.getString(
+                R.string.system_update_settings_list_item_title), R.drawable.ic_system_update);
+        mContext = context;
+    }
+
+    @Override
+    public CharSequence getDesc() {
+        return null;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+
+    @Override
+    public void onClick() {
+        // TODO: trigger system OTA flow
+    }
+}