- refact to use fragments
- use AppCompatActivity so the app bar is more customizable
- switch couple more setting page to use pagedList pattern
Test: manually verified
Change-Id: I936006c07c79e43cc02640916450493a90bcfe3b
diff --git a/src/com/android/car/settings/applications/ApplicationDetailActivity.java b/src/com/android/car/settings/applications/ApplicationDetailFragment.java
similarity index 60%
rename from src/com/android/car/settings/applications/ApplicationDetailActivity.java
rename to src/com/android/car/settings/applications/ApplicationDetailFragment.java
index a5bc882..eb117b1 100644
--- a/src/com/android/car/settings/applications/ApplicationDetailActivity.java
+++ b/src/com/android/car/settings/applications/ApplicationDetailFragment.java
@@ -18,7 +18,6 @@
import android.app.Activity;
import android.app.ActivityManager;
import android.app.admin.DevicePolicyManager;
-import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -26,22 +25,18 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
import android.icu.text.ListFormatter;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.ImageView;
import android.widget.TextView;
-import com.android.car.settings.common.AnimationUtil;
-import com.android.car.settings.common.CarSettingActivity;
import com.android.car.settings.R;
+import com.android.car.settings.common.ListSettingsFragment;
+import com.android.car.settings.common.TypedPagedListAdapter;
import com.android.settingslib.Utils;
import com.android.settingslib.applications.PermissionsSummaryHelper;
import com.android.settingslib.applications.PermissionsSummaryHelper.PermissionsResultCallback;
@@ -54,47 +49,46 @@
* Shows details about an application and action associated with that application,
* like uninstall, forceStop.
*/
-public class ApplicationDetailActivity extends CarSettingActivity {
+public class ApplicationDetailFragment extends ListSettingsFragment {
private static final String TAG = "AppDetailActivity";
- /**
- * Key for ResolvedInfo in bundle passed in.
- */
- public static final String APPLICATION_INFO_KEY = "APPLICATION_INFO_KEY";
+ public static final String EXTRA_RESOLVE_INFO = "extra_resolve_info";
private ResolveInfo mResolveInfo;
- private TextView mPermissionDetailView;
- private View mPermissionContainer;
- private Button mDisableToggle;
- private Button mForceStopButton;
+
+ private TextView mDisableToggle;
+ private TextView mForceStopButton;
private DevicePolicyManager mDpm;
+ public static ApplicationDetailFragment getInstance(ResolveInfo resolveInfo) {
+ ApplicationDetailFragment applicationDetailFragment = new ApplicationDetailFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putParcelable(EXTRA_RESOLVE_INFO, resolveInfo);
+ bundle.putInt(EXTRA_TITLE_ID, R.string.applications_settings);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+ applicationDetailFragment.setArguments(bundle);
+ return applicationDetailFragment;
+ }
+
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.application_details);
- if (getIntent() != null && getIntent().getExtras() != null) {
- mResolveInfo = getIntent().getExtras().getParcelable(APPLICATION_INFO_KEY);
- }
+ mResolveInfo = getArguments().getParcelable(EXTRA_RESOLVE_INFO);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
if (mResolveInfo == null) {
Log.w(TAG, "No application info set.");
return;
}
- mDisableToggle = (Button) findViewById(R.id.disable_toggle);
- mForceStopButton = (Button) findViewById(R.id.force_stop);
+ mDisableToggle = (TextView) getActivity().findViewById(R.id.action_button1);
+ mForceStopButton = (TextView) getActivity().findViewById(R.id.action_button2);
+ mForceStopButton.setText(R.string.force_stop);
+ mForceStopButton.setVisibility(View.VISIBLE);
- mPermissionDetailView = (TextView) findViewById(R.id.permission_detail);
- mPermissionContainer = findViewById(R.id.permission_container);
-
- ImageView icon = (ImageView) findViewById(R.id.icon);
- icon.setImageDrawable(mResolveInfo.loadIcon(getPackageManager()));
-
- TextView appName = (TextView) findViewById(R.id.title);
- appName.setText(mResolveInfo.loadLabel(getPackageManager()));
-
- PermissionsSummaryHelper.getPermissionSummary(this /* context */,
- mResolveInfo.activityInfo.packageName, mPermissionCallback);
- mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
+ mDpm = (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
updateForceStopButton();
mForceStopButton.setOnClickListener(v -> {
forceStopPackage(mResolveInfo.activityInfo.packageName);
@@ -102,10 +96,23 @@
updateDisableable();
}
+ @Override
+ public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
+ ArrayList<TypedPagedListAdapter.LineItem> items = new ArrayList<>();
+ items.add(new ApplicationLineItem(
+ getContext(),
+ getContext().getPackageManager(),
+ mResolveInfo,
+ null /* fragmentController */,
+ false));
+ items.add(new ApplicationPermissionLineItem(getContext(), mResolveInfo));
+ return items;
+ }
+
// fetch the latest ApplicationInfo instead of caching it so it reflects the current state.
private ApplicationInfo getAppInfo() {
try {
- return getPackageManager().getApplicationInfo(
+ return getContext().getPackageManager().getApplicationInfo(
mResolveInfo.activityInfo.packageName, 0 /* flag */);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "incorrect packagename: " + mResolveInfo.activityInfo.packageName, e);
@@ -115,7 +122,7 @@
private PackageInfo getPackageInfo() {
try {
- return getPackageManager().getPackageInfo(
+ return getContext().getPackageManager().getPackageInfo(
mResolveInfo.activityInfo.packageName, 0 /* flag */);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "incorrect packagename: " + mResolveInfo.activityInfo.packageName, e);
@@ -128,7 +135,8 @@
boolean disabled = false;
// Try to prevent the user from bricking their phone
// by not allowing disabling of apps in the system.
- if (Utils.isSystemPackage(getResources(), getPackageManager(), getPackageInfo())) {
+ if (Utils.isSystemPackage(
+ getResources(), getContext().getPackageManager(), getPackageInfo())) {
// Disable button for core system applications.
mDisableToggle.setText(R.string.disable_text);
disabled = false;
@@ -146,7 +154,7 @@
? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
mDisableToggle.setOnClickListener(v -> {
- getPackageManager().setApplicationEnabledSetting(
+ getContext().getPackageManager().setApplicationEnabledSetting(
mResolveInfo.activityInfo.packageName,
enableState,
0);
@@ -160,7 +168,7 @@
}
private void forceStopPackage(String pkgName) {
- ActivityManager am = (ActivityManager) getSystemService(
+ ActivityManager am = (ActivityManager) getContext().getSystemService(
Context.ACTIVITY_SERVICE);
Log.d(TAG, "Stopping package " + pkgName);
am.forceStopPackage(pkgName);
@@ -197,7 +205,7 @@
Log.d(TAG, "Sending broadcast to query restart for "
+ mResolveInfo.activityInfo.packageName);
}
- sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
+ getActivity().sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
mCheckKillProcessesReceiver, null, Activity.RESULT_CANCELED, null, null);
}
}
@@ -214,51 +222,4 @@
mForceStopButton.setEnabled(enabled);
}
};
-
- private final PermissionsResultCallback mPermissionCallback
- = new PermissionsResultCallback() {
- @Override
- public void onPermissionSummaryResult(int standardGrantedPermissionCount,
- int requestedPermissionCount, int additionalGrantedPermissionCount,
- List<CharSequence> grantedGroupLabels) {
- Resources res = getResources();
- CharSequence summary = null;
-
- if (requestedPermissionCount == 0) {
- summary = res.getString(
- R.string.runtime_permissions_summary_no_permissions_requested);
- mPermissionContainer.setEnabled(false);
- mPermissionContainer.setOnClickListener(null);
- } else {
- ArrayList<CharSequence> list = new ArrayList<>(grantedGroupLabels);
- if (additionalGrantedPermissionCount > 0) {
- // N additional permissions.
- list.add(res.getQuantityString(
- R.plurals.runtime_permissions_additional_count,
- additionalGrantedPermissionCount, additionalGrantedPermissionCount));
- }
- if (list.size() == 0) {
- summary = res.getString(
- R.string.runtime_permissions_summary_no_permissions_granted);
- } else {
- summary = ListFormatter.getInstance().format(list);
- }
- mPermissionContainer.setEnabled(true);
- mPermissionContainer.setOnClickListener(mPermissionClickedListener);
- }
- mPermissionDetailView.setText(summary);
- }
- };
-
- private OnClickListener mPermissionClickedListener = (v) -> {
- // start new activity to manage app permissions
- Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
- intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mResolveInfo.activityInfo.packageName);
- try {
- startActivity(intent, AnimationUtil.slideInFromRightOption(
- ApplicationDetailActivity.this).toBundle());
- } catch (ActivityNotFoundException e) {
- Log.w(TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
- }
- };
}
diff --git a/src/com/android/car/settings/applications/ApplicationLineItem.java b/src/com/android/car/settings/applications/ApplicationLineItem.java
index 48625c6..c168290 100644
--- a/src/com/android/car/settings/applications/ApplicationLineItem.java
+++ b/src/com/android/car/settings/applications/ApplicationLineItem.java
@@ -18,12 +18,11 @@
import android.annotation.NonNull;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.widget.ImageView;
-import com.android.car.settings.common.AnimationUtil;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.IconTextLineItem;
/**
@@ -33,28 +32,41 @@
private final ResolveInfo mResolveInfo;
private final Context mContext;
private final PackageManager mPm;
+ private final boolean mClickable;
+ private final BaseFragment.FragmentController mFragmentController;
public ApplicationLineItem(
- @NonNull Context context, PackageManager pm, ResolveInfo resolveInfo) {
+ @NonNull Context context,
+ PackageManager pm,
+ ResolveInfo resolveInfo,
+ BaseFragment.FragmentController fragmentController) {
+ this(context, pm, resolveInfo, fragmentController, true);
+ }
+
+ public ApplicationLineItem(
+ @NonNull Context context,
+ PackageManager pm,
+ ResolveInfo resolveInfo,
+ BaseFragment.FragmentController fragmentController,
+ boolean clickable) {
super(resolveInfo.loadLabel(pm));
mContext = context;
mPm = pm;
mResolveInfo = resolveInfo;
+ mFragmentController = fragmentController;
+ mClickable = clickable;
}
-
@Override
public void onClick() {
- Intent intent = new Intent(mContext, ApplicationDetailActivity.class);
- intent.putExtra(
- ApplicationDetailActivity.APPLICATION_INFO_KEY, mResolveInfo);
- mContext.startActivity(
- intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ if (mClickable) {
+ mFragmentController.launchFragment(ApplicationDetailFragment.getInstance(mResolveInfo));
+ }
}
@Override
public boolean isEnabled() {
- return true;
+ return mClickable;
}
@Override
diff --git a/src/com/android/car/settings/applications/ApplicationListAdapter.java b/src/com/android/car/settings/applications/ApplicationListAdapter.java
deleted file mode 100644
index 625cf73..0000000
--- a/src/com/android/car/settings/applications/ApplicationListAdapter.java
+++ /dev/null
@@ -1,121 +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.applications;
-
-import android.annotation.NonNull;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.support.v7.widget.RecyclerView;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import com.android.car.settings.R;
-import com.android.car.view.PagedListView;
-import com.android.car.settings.common.AnimationUtil;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Renders {@link android.content.pm.ApplicationInfo} to a view to be displayed as a row in a list.
- */
-public class ApplicationListAdapter
- extends RecyclerView.Adapter<ApplicationListAdapter.ViewHolder>
- implements PagedListView.ItemCap {
- private static final String TAG = "ApplicationListAdapter";
-
- private final Context mContext;
- private final PackageManager mPm;
-
- private List<ResolveInfo> mResolveInfos;
-
- public ApplicationListAdapter(@NonNull Context context, PackageManager pm) {
- mContext = context;
- mPm = pm;
- Intent intent= new Intent(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- mResolveInfos = pm.queryIntentActivities(intent,
- PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
- | PackageManager.MATCH_DISABLED_COMPONENTS);
-
- Collections.sort(mResolveInfos, new ResolveInfo.DisplayNameComparator(mPm));
- }
-
- public boolean isEmpty() {
- return mResolveInfos.isEmpty();
- }
-
- public class ViewHolder extends RecyclerView.ViewHolder {
- private final ImageView mIcon;
- private final TextView mTitle;
-
- public ViewHolder(View view) {
- super(view);
- mTitle = (TextView) view.findViewById(R.id.title);
- mIcon = (ImageView) view.findViewById(R.id.icon);
- }
- }
-
- private class ApplicationInfoClickListener implements OnClickListener {
- private final int mPosition;
-
- public ApplicationInfoClickListener(int position) {
- mPosition = position;
- }
-
- @Override
- public void onClick(View v) {
- ResolveInfo resolveInfo = mResolveInfos.get(mPosition);
- Intent intent = new Intent(mContext, ApplicationDetailActivity.class);
- intent.putExtra(
- ApplicationDetailActivity.APPLICATION_INFO_KEY, resolveInfo);
- mContext.startActivity(
- intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
- }
- };
-
- @Override
- public ApplicationListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
- int viewType) {
- View v = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.icon_widget_line_item, parent, false);
- return new ViewHolder(v);
- }
-
- @Override
- public void onBindViewHolder(ViewHolder holder, int position) {
- ResolveInfo resolveInfo = mResolveInfos.get(position);
- holder.mTitle.setText(resolveInfo.loadLabel(mPm));
- holder.mIcon.setImageDrawable(resolveInfo.loadIcon(mPm));
- holder.itemView.setOnClickListener(new ApplicationInfoClickListener(position));
- }
-
- @Override
- public int getItemCount() {
- return mResolveInfos.size();
- }
-
- @Override
- public void setMaxItems(int maxItems) {
- // no limit in this list.
- }
-}
diff --git a/src/com/android/car/settings/applications/ApplicationPermissionLineItem.java b/src/com/android/car/settings/applications/ApplicationPermissionLineItem.java
new file mode 100644
index 0000000..bd7298c
--- /dev/null
+++ b/src/com/android/car/settings/applications/ApplicationPermissionLineItem.java
@@ -0,0 +1,127 @@
+/*
+ * 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.applications;
+
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.icu.text.ListFormatter;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.AnimationUtil;
+import com.android.car.settings.common.TextLineItem;
+import com.android.settingslib.Utils;
+import com.android.settingslib.applications.PermissionsSummaryHelper;
+import com.android.settingslib.applications.PermissionsSummaryHelper.PermissionsResultCallback;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Shows details about an application and action associated with that application,
+ * like uninstall, forceStop.
+ */
+public class ApplicationPermissionLineItem extends TextLineItem {
+ private static final String TAG = "AppPermissionLineItem";
+
+ private final ResolveInfo mResolveInfo;
+ private final Context mContext;
+ private TextLineItem.ViewHolder mViewHolder;
+ private CharSequence mSummary;
+
+ public ApplicationPermissionLineItem(Context context, ResolveInfo resolveInfo) {
+ super(context.getText(R.string.permissions_label));
+ mResolveInfo = resolveInfo;
+ mContext = context;
+
+ PermissionsSummaryHelper.getPermissionSummary(mContext,
+ mResolveInfo.activityInfo.packageName, mPermissionCallback);
+ }
+
+ @Override
+ public void bindViewHolder(TextLineItem.ViewHolder viewHolder) {
+ mViewHolder = viewHolder;
+ viewHolder.titleView.setText(mTitle);
+ if (TextUtils.isEmpty(mSummary)) {
+ viewHolder.itemView.setOnClickListener(null);
+ viewHolder.descView.setText(R.string.computing_size);
+ viewHolder.itemView.setEnabled(false);
+ } else {
+ viewHolder.itemView.setOnClickListener(mOnClickListener);
+ viewHolder.descView.setText(mSummary);
+ viewHolder.itemView.setEnabled(true);
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return false;
+ }
+
+ @Override
+ public CharSequence getDesc() {
+ return null;
+ }
+
+ @Override
+ public void onClick() {
+ // start new activity to manage app permissions
+ Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
+ intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mResolveInfo.activityInfo.packageName);
+ try {
+ mContext.startActivity(
+ intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
+ }
+ }
+
+ private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
+ @Override
+ public void onPermissionSummaryResult(int standardGrantedPermissionCount,
+ int requestedPermissionCount, int additionalGrantedPermissionCount,
+ List<CharSequence> grantedGroupLabels) {
+ Resources res = mContext.getResources();
+
+ if (requestedPermissionCount == 0) {
+ mSummary = res.getString(
+ R.string.runtime_permissions_summary_no_permissions_requested);
+ } else {
+ ArrayList<CharSequence> list = new ArrayList<>(grantedGroupLabels);
+ if (additionalGrantedPermissionCount > 0) {
+ // N additional permissions.
+ list.add(res.getQuantityString(
+ R.plurals.runtime_permissions_additional_count,
+ additionalGrantedPermissionCount, additionalGrantedPermissionCount));
+ }
+ if (list.size() == 0) {
+ mSummary = res.getString(
+ R.string.runtime_permissions_summary_no_permissions_granted);
+ } else {
+ mSummary = ListFormatter.getInstance().format(list);
+ }
+ }
+ if (mViewHolder != null) {
+ bindViewHolder(mViewHolder);
+ }
+ }
+ };
+}
diff --git a/src/com/android/car/settings/applications/ApplicationSettingsActivity.java b/src/com/android/car/settings/applications/ApplicationSettingsFragment.java
similarity index 68%
rename from src/com/android/car/settings/applications/ApplicationSettingsActivity.java
rename to src/com/android/car/settings/applications/ApplicationSettingsFragment.java
index ed0b19a..fa8cdb3 100644
--- a/src/com/android/car/settings/applications/ApplicationSettingsActivity.java
+++ b/src/com/android/car/settings/applications/ApplicationSettingsFragment.java
@@ -20,7 +20,8 @@
import android.content.pm.ResolveInfo;
import android.os.Bundle;
-import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.R;
+import com.android.car.settings.common.ListSettingsFragment;
import com.android.car.settings.common.TypedPagedListAdapter;
import java.util.ArrayList;
@@ -29,16 +30,19 @@
/**
* Lists all installed applications and their summary.
*/
-public class ApplicationSettingsActivity extends ListSettingsActivity {
+public class ApplicationSettingsFragment extends ListSettingsFragment {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ public static ApplicationSettingsFragment getInstance() {
+ ApplicationSettingsFragment applicationSettingsFragment = new ApplicationSettingsFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.applications_settings);
+ applicationSettingsFragment.setArguments(bundle);
+ return applicationSettingsFragment;
}
@Override
public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
- PackageManager pm = getPackageManager();
+ PackageManager pm = getContext().getPackageManager();
Intent intent= new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent,
@@ -46,7 +50,7 @@
| PackageManager.MATCH_DISABLED_COMPONENTS);
ArrayList<TypedPagedListAdapter.LineItem> items = new ArrayList<>();
for (ResolveInfo resolveInfo : resolveInfos) {
- items.add(new ApplicationLineItem(this, pm, resolveInfo));
+ items.add(new ApplicationLineItem(getContext(), pm, resolveInfo, mFragmentController));
}
return items;
}
diff --git a/src/com/android/car/settings/bluetooth/BluetoothDetailActivity.java b/src/com/android/car/settings/bluetooth/BluetoothDetailFragment.java
similarity index 71%
rename from src/com/android/car/settings/bluetooth/BluetoothDetailActivity.java
rename to src/com/android/car/settings/bluetooth/BluetoothDetailFragment.java
index 152c383..508412d 100644
--- a/src/com/android/car/settings/bluetooth/BluetoothDetailActivity.java
+++ b/src/com/android/car/settings/bluetooth/BluetoothDetailFragment.java
@@ -21,10 +21,10 @@
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
-import android.widget.Button;
import android.widget.EditText;
+import android.widget.TextView;
-import com.android.car.settings.common.CarSettingActivity;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.R;
import com.android.car.settings.common.NoDividerItemDecoration;
import com.android.car.settings.common.TypedPagedListAdapter;
@@ -45,37 +45,52 @@
* 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 implements
+public class BluetoothDetailFragment extends BaseFragment implements
BluetoothProfileLineItem.DataChangedListener {
- private static final String TAG = "BluetoothDetailActivity";
- public static final String BT_DEVICE_KEY = "btDeviceKey";
+ private static final String TAG = "BluetoothDetailFragment";
+
+ public static final String EXTRA_BT_DEVICE = "extra_bt_device";
private BluetoothDevice mDevice;
private CachedBluetoothDevice mCachedDevice;
+
private PagedListView mListView;
private TypedPagedListAdapter mPagedListAdapter;
- private LocalBluetoothManager mLocalManager;
private CachedBluetoothDeviceManager mDeviceManager;
+ private LocalBluetoothManager mLocalManager;
private EditText mNameView;
- private Button mOkButton;
+ private TextView mOkButton;
+
+ public static BluetoothDetailFragment getInstance(BluetoothDevice btDevice) {
+ BluetoothDetailFragment bluetoothDetailFragment = new BluetoothDetailFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putParcelable(EXTRA_BT_DEVICE, btDevice);
+ bundle.putInt(EXTRA_TITLE_ID, R.string.bluetooth_settings);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.bluetooth_details);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+ bluetoothDetailFragment.setArguments(bundle);
+ return bluetoothDetailFragment;
+ }
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.bluetooth_details);
- mListView = (PagedListView) findViewById(R.id.list);
- mListView.setDefaultItemDecoration(new NoDividerItemDecoration(this));
+ mDevice = getArguments().getParcelable(EXTRA_BT_DEVICE);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mListView = (PagedListView) getView().findViewById(R.id.list);
+ mListView.setDefaultItemDecoration(new NoDividerItemDecoration(getContext()));
mListView.setDarkMode();
- if (getIntent() != null && getIntent().getExtras() != null) {
- mDevice = getIntent().getExtras().getParcelable(BT_DEVICE_KEY);
- }
if (mDevice == null) {
Log.w(TAG, "No bluetooth device set.");
return;
}
- mLocalManager = LocalBluetoothManager.getInstance(this /* context */ , null /* listener */);
+ mLocalManager = LocalBluetoothManager.getInstance(getContext(), null /* listener */);
if (mLocalManager == null) {
Log.e(TAG, "Bluetooth is not supported on this device");
return;
@@ -89,23 +104,16 @@
mDevice);
}
- mNameView = (EditText) findViewById(R.id.bt_name);
- mNameView.setText(mDevice.getName());
+ mNameView = (EditText) getView().findViewById(R.id.bt_name);
+ mNameView.setText(mCachedDevice.getName());
setupForgetButton();
setupOkButton();
- mPagedListAdapter = new TypedPagedListAdapter(this /* context */, getProfileLineItems());
+ mPagedListAdapter = new TypedPagedListAdapter(getContext(), getProfileLineItems());
mListView.setAdapter(mPagedListAdapter);
}
@Override
- public void setupActionBar() {
- super.setupActionBar();
- getActionBar().setCustomView(R.layout.action_bar_with_button);
- getActionBar().setDisplayShowCustomEnabled(true);
- }
-
- @Override
public void onDataChanged() {
mPagedListAdapter.notifyDataSetChanged();
}
@@ -114,7 +122,7 @@
ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
lineItems.add(new BluetoothProfileLineItem(
- this /* context */, profile, mCachedDevice, this));
+ getContext(), profile, mCachedDevice, this));
}
int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
@@ -122,30 +130,30 @@
if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
PbapServerProfile psp = mLocalManager.getProfileManager().getPbapProfile();
lineItems.add(new BluetoothProfileLineItem(
- this /* context */, psp, mCachedDevice, this));
+ getContext(), 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));
+ getContext(), mapProfile, mCachedDevice, this));
}
return lineItems;
}
private void setupForgetButton() {
- Button fortgetButton = (Button) findViewById(R.id.action_button2);
+ TextView fortgetButton = (TextView) getActivity().findViewById(R.id.action_button2);
fortgetButton.setVisibility(View.VISIBLE);
fortgetButton.setText(R.string.forget);
fortgetButton.setOnClickListener(v -> {
mCachedDevice.unpair();
- finish();
+ mFragmentController.goBack();
});
}
private void setupOkButton() {
- mOkButton = (Button) findViewById(R.id.action_button1);
+ mOkButton = (TextView) getActivity().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);
@@ -162,12 +170,12 @@
@Override
public void afterTextChanged(Editable s) {
- mOkButton.setEnabled(!s.toString().equals(mDevice.getName()));
+ mOkButton.setEnabled(!s.toString().equals(mCachedDevice.getName()));
}
});
mOkButton.setOnClickListener(v -> {
mCachedDevice.setName(mNameView.getText().toString());
- finish();
+ mFragmentController.goBack();
});
}
}
diff --git a/src/com/android/car/settings/bluetooth/BluetoothDeviceListAdapter.java b/src/com/android/car/settings/bluetooth/BluetoothDeviceListAdapter.java
index c472c85..341f5d9 100644
--- a/src/com/android/car/settings/bluetooth/BluetoothDeviceListAdapter.java
+++ b/src/com/android/car/settings/bluetooth/BluetoothDeviceListAdapter.java
@@ -20,7 +20,6 @@
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
-import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Handler;
@@ -38,8 +37,8 @@
import android.widget.Toast;
import com.android.car.settings.R;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.view.PagedListView;
-import com.android.car.settings.common.AnimationUtil;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -76,6 +75,7 @@
private final LocalBluetoothManager mLocalManager;
private final CachedBluetoothDeviceManager mDeviceManager;
private final Context mContext;
+ private final BaseFragment.FragmentController mFragmentController;
/* Talk-back descriptions for various BT icons */
public final String mComputerDescription;
@@ -110,9 +110,12 @@
}
public BluetoothDeviceListAdapter(
- Context context, LocalBluetoothManager localBluetoothManager) {
+ Context context,
+ LocalBluetoothManager localBluetoothManager,
+ BaseFragment.FragmentController fragmentController) {
mContext = context;
mLocalManager = localBluetoothManager;
+ mFragmentController = fragmentController;
mLocalAdapter = mLocalManager.getBluetoothAdapter();
mDeviceManager = mLocalManager.getCachedDeviceManager();
@@ -153,12 +156,14 @@
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
switch (viewType) {
case BONDED_DEVICE_HEADER_TYPE:
- v = layoutInflater.inflate(R.layout.in_list_header, parent, false);
- ((TextView) v).setText(R.string.bluetooth_preference_paired_devices);
+ v = layoutInflater.inflate(R.layout.text_line_item, parent, false);
+ ((TextView) v.findViewById(R.id.title)).setText(
+ R.string.bluetooth_preference_paired_devices);
break;
case AVAILABLE_DEVICE_HEADER_TYPE:
- v = layoutInflater.inflate(R.layout.in_list_header, parent, false);
- ((TextView) v).setText(R.string.bluetooth_preference_found_devices);
+ v = layoutInflater.inflate(R.layout.text_line_item, parent, false);
+ ((TextView) v.findViewById(R.id.title)).setText(
+ R.string.bluetooth_preference_found_devices);
break;
default:
v = layoutInflater.inflate(R.layout.icon_widget_line_item, parent, false);
@@ -200,11 +205,8 @@
if (BluetoothDeviceFilter.BONDED_DEVICE_FILTER.matches(bluetoothDevice.getDevice())) {
holder.mActionButton.setVisibility(View.VISIBLE);
holder.mActionButton.setOnClickListener(v -> {
- Intent intent = new Intent(mContext, BluetoothDetailActivity.class);
- intent.putExtra(
- BluetoothDetailActivity.BT_DEVICE_KEY, bluetoothDevice.getDevice());
- mContext.startActivity(
- intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(
+ BluetoothDetailFragment.getInstance(bluetoothDevice.getDevice()));
});
} else {
holder.mActionButton.setVisibility(View.GONE);
diff --git a/src/com/android/car/settings/bluetooth/BluetoothSettingsActivity.java b/src/com/android/car/settings/bluetooth/BluetoothSettingsFragment.java
similarity index 76%
rename from src/com/android/car/settings/bluetooth/BluetoothSettingsActivity.java
rename to src/com/android/car/settings/bluetooth/BluetoothSettingsFragment.java
index 15ca09e..4aac3b2 100644
--- a/src/com/android/car/settings/bluetooth/BluetoothSettingsActivity.java
+++ b/src/com/android/car/settings/bluetooth/BluetoothSettingsFragment.java
@@ -19,13 +19,14 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
+import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.ViewSwitcher;
-import com.android.car.settings.common.CarSettingActivity;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.R;
import com.android.car.view.PagedListView;
@@ -36,10 +37,10 @@
import com.android.settingslib.bluetooth.LocalBluetoothManager;
/**
- * Activity to host Bluetooth related preferences.
+ * Hosts Bluetooth related preferences.
*/
-public class BluetoothSettingsActivity extends CarSettingActivity implements BluetoothCallback {
- private static final String TAG = "BluetoothSettingsActivity";
+public class BluetoothSettingsFragment extends BaseFragment implements BluetoothCallback {
+ private static final String TAG = "BluetoothSettingsFragment";
private Switch mBluetoothSwitch;
private ProgressBar mProgressBar;
@@ -50,13 +51,20 @@
private LocalBluetoothAdapter mLocalAdapter;
private LocalBluetoothManager mLocalManager;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.bluetooth_list);
+ public static BluetoothSettingsFragment getInstance() {
+ BluetoothSettingsFragment bluetoothSettingsFragment = new BluetoothSettingsFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.bluetooth_settings);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.bluetooth_list);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_toggle);
+ bluetoothSettingsFragment.setArguments(bundle);
+ return bluetoothSettingsFragment;
+ }
- ((TextView) findViewById(R.id.title)).setText(R.string.bluetooth_settings);
- mBluetoothSwitch = (Switch) findViewById(R.id.toggle_switch);
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mBluetoothSwitch = (Switch) getActivity().findViewById(R.id.toggle_switch);
mBluetoothSwitch.setOnClickListener(v -> {
if (mBluetoothSwitch.isChecked()) {
// bt scan was turned on at state listener, when state is on.
@@ -67,40 +75,34 @@
}
});
- mProgressBar = (ProgressBar) findViewById(R.id.bt_search_progress);
- mDeviceListView = (PagedListView) findViewById(R.id.list);
- mViewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
- mMessageView = (TextView) findViewById(R.id.bt_message);
+ mProgressBar = (ProgressBar) getView().findViewById(R.id.bt_search_progress);
+ mDeviceListView = (PagedListView) getView().findViewById(R.id.list);
+ mViewSwitcher = (ViewSwitcher) getView().findViewById(R.id.view_switcher);
+ mMessageView = (TextView) getView().findViewById(R.id.bt_message);
- mLocalManager = LocalBluetoothManager.getInstance(this /* context */ , null /* listener */);
+ mLocalManager = LocalBluetoothManager.getInstance(getContext(), null /* listener */);
if (mLocalManager == null) {
Log.e(TAG, "Bluetooth is not supported on this device");
return;
}
mLocalAdapter = mLocalManager.getBluetoothAdapter();
- mDeviceListView.setDefaultItemDecoration(new PagedListView.Decoration(this));
+ mDeviceListView.setDefaultItemDecoration(new PagedListView.Decoration(getContext()));
// Set this to light mode, since the scroll bar buttons always appear
// on top of a dark scrim.
mDeviceListView.setDarkMode();
- mDeviceAdapter = new BluetoothDeviceListAdapter(this /* context */ , mLocalManager);
+ mDeviceAdapter = new BluetoothDeviceListAdapter(
+ getContext() , mLocalManager, mFragmentController);
mDeviceListView.setAdapter(mDeviceAdapter);
}
@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) {
return;
}
- mLocalManager.setForegroundActivity(this);
+ mLocalManager.setForegroundActivity(getActivity());
mLocalManager.getEventManager().registerCallback(this);
mBluetoothSwitch.setChecked(mLocalAdapter.isEnabled());
if (mLocalAdapter.isEnabled()) {
diff --git a/src/com/android/car/settings/common/BaseFragment.java b/src/com/android/car/settings/common/BaseFragment.java
new file mode 100644
index 0000000..819f30c
--- /dev/null
+++ b/src/com/android/car/settings/common/BaseFragment.java
@@ -0,0 +1,118 @@
+/*
+ * 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.Fragment;
+import android.os.Bundle;
+import android.support.annotation.LayoutRes;
+import android.support.annotation.StringRes;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.android.car.settings.R;
+
+import java.util.Set;
+
+/**
+ * Base fragment for setting activity.
+ */
+public abstract class BaseFragment extends Fragment {
+ public static final String EXTRA_TITLE_ID = "extra_title_id";
+ public static final String EXTRA_LAYOUT = "extra_layout";
+ public static final String EXTRA_ACTION_BAR_LAYOUT = "extra_action_bar_layout";
+
+ /**
+ * Controls the transition of fragment.
+ */
+ public interface FragmentController {
+ /**
+ * Launches fragment in the main container of current activity.
+ */
+ void launchFragment(BaseFragment fragment);
+
+ /**
+ * Pops the top off the fragment stack.
+ */
+ void goBack();
+ }
+
+ @LayoutRes
+ protected int mLayout;
+
+ @LayoutRes
+ private int mActionBarLayout;
+
+ @StringRes
+ private int mTitleId;
+
+ protected FragmentController mFragmentController;
+
+ public void setFragmentController(FragmentController fragmentController) {
+ mFragmentController = fragmentController;
+ }
+
+ protected static Bundle getBundle() {
+ Bundle bundle = new Bundle();
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar);
+ return bundle;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Set<String> extraKeys = getArguments().keySet();
+ if (extraKeys.contains(EXTRA_ACTION_BAR_LAYOUT)) {
+ mActionBarLayout = getArguments().getInt(EXTRA_ACTION_BAR_LAYOUT);
+ } else {
+ throw new IllegalArgumentException("must specify a actionBar layout");
+ }
+ if (extraKeys.contains(EXTRA_LAYOUT)) {
+ mLayout = getArguments().getInt(EXTRA_LAYOUT);
+ } else {
+ throw new IllegalArgumentException("must specify a layout");
+ }
+ if (extraKeys.contains(EXTRA_TITLE_ID)) {
+ mTitleId = getArguments().getInt(EXTRA_TITLE_ID);
+ } else {
+ throw new IllegalArgumentException("must specify a title");
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ return inflater.inflate(mLayout, container, false);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setCustomView(mActionBarLayout);
+ actionBar.setDisplayShowCustomEnabled(true);
+ // make the toolbar take the whole width.
+ Toolbar toolbar=(Toolbar)actionBar.getCustomView().getParent();
+ toolbar.setPadding(0, 0, 0, 0);
+ ((TextView) getActivity().findViewById(R.id.title)).setText(mTitleId);
+ }
+}
diff --git a/src/com/android/car/settings/common/CarSettingActivity.java b/src/com/android/car/settings/common/CarSettingActivity.java
index 642ea30..f705ae3 100644
--- a/src/com/android/car/settings/common/CarSettingActivity.java
+++ b/src/com/android/car/settings/common/CarSettingActivity.java
@@ -15,29 +15,61 @@
*/
package com.android.car.settings.common;
-import android.app.Activity;
import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.android.car.settings.R;
+import com.android.car.settings.home.HomepageFragment;
/**
* Base activity class for car settings, provides a action bar with a back button that goes to
* previous activity.
*/
-public class CarSettingActivity extends Activity {
+public class CarSettingActivity extends AppCompatActivity implements
+ BaseFragment.FragmentController {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setupActionBar();
+ setContentView(R.layout.app_compat_activity);
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ HomepageFragment homepageFragment = HomepageFragment.getInstance();
+ homepageFragment.setFragmentController(this);
+ launchFragment(homepageFragment);
}
- /**
- * Add logic to setup ActionBar here.
- */
- public void setupActionBar() {
- getActionBar().setDisplayHomeAsUpEnabled(true);
+ @Override
+ public void launchFragment(BaseFragment fragment) {
+ fragment.setFragmentController(this);
+ getFragmentManager()
+ .beginTransaction()
+ .setCustomAnimations(
+ R.animator.trans_right_in ,
+ R.animator.trans_left_out,
+ R.animator.trans_left_in,
+ R.animator.trans_right_out)
+ .replace(R.id.fragment_container, fragment)
+ .addToBackStack(null)
+ .commit();
+ }
+
+ @Override
+ public void goBack() {
+ if (getFragmentManager().getBackStackEntryCount() > 0) {
+ getFragmentManager().popBackStack();
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (getFragmentManager().getBackStackEntryCount() > 0) {
+ getFragmentManager().popBackStack();
+ } else {
+ super.onBackPressed();
+ }
}
/**
@@ -47,7 +79,6 @@
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
- overridePendingTransition(R.anim.trans_fade_in, R.anim.trans_right_out);
return true;
}
return super.onOptionsItemSelected(item);
diff --git a/src/com/android/car/settings/common/ListSettingsActivity.java b/src/com/android/car/settings/common/ListSettingsFragment.java
similarity index 67%
rename from src/com/android/car/settings/common/ListSettingsActivity.java
rename to src/com/android/car/settings/common/ListSettingsFragment.java
index 9088c3a..c20d52c 100644
--- a/src/com/android/car/settings/common/ListSettingsActivity.java
+++ b/src/com/android/car/settings/common/ListSettingsFragment.java
@@ -18,6 +18,9 @@
import android.os.Bundle;
+import android.support.annotation.LayoutRes;
+import android.support.annotation.StringRes;
+
import com.android.car.settings.R;
import com.android.car.view.PagedListView;
@@ -26,20 +29,25 @@
/**
* Settings page that only contain a list of items.
*/
-public abstract class ListSettingsActivity extends CarSettingActivity {
+public abstract class ListSettingsFragment extends BaseFragment {
private PagedListView mListView;
protected TypedPagedListAdapter mPagedListAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.list);
+ protected static Bundle getBundle() {
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_LAYOUT, R.layout.list);
+ return bundle;
+ }
- mListView = (PagedListView) findViewById(R.id.list);
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ mListView = (PagedListView) getView().findViewById(R.id.list);
mListView.setDefaultItemDecoration(getDecoration());
mListView.setDarkMode();
- mPagedListAdapter = new TypedPagedListAdapter(this /* context */, getLineItems());
+ mPagedListAdapter = new TypedPagedListAdapter(getContext(), getLineItems());
mListView.setAdapter(mPagedListAdapter);
}
@@ -52,6 +60,6 @@
* Gets decoration for the list view.
*/
protected PagedListView.Decoration getDecoration() {
- return new PagedListView.Decoration(this);
+ return new PagedListView.Decoration(getContext());
}
}
diff --git a/src/com/android/car/settings/common/SimpleIconLineItem.java b/src/com/android/car/settings/common/SimpleIconLineItem.java
index 967464e..dcdc910 100644
--- a/src/com/android/car/settings/common/SimpleIconLineItem.java
+++ b/src/com/android/car/settings/common/SimpleIconLineItem.java
@@ -16,16 +16,11 @@
package com.android.car.settings.common;
-import android.app.ActivityOptions;
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 android.widget.ImageView;
import com.android.car.settings.R;
@@ -36,20 +31,23 @@
public class SimpleIconLineItem extends IconTextLineItem {
private final CharSequence mDesc;
private final Context mContext;
- private final Class mActivityClass;
+ private final BaseFragment mFragment;
private final @DrawableRes int mIconRes;
+ private final BaseFragment.FragmentController mFragmentController;
public SimpleIconLineItem(
@StringRes int title,
@DrawableRes int iconRes,
Context context,
CharSequence desc,
- Class activityClass) {
+ BaseFragment fragment,
+ BaseFragment.FragmentController fragmentController) {
super(context.getText(title));
mDesc = desc;
mContext = context;
- mActivityClass = activityClass;
+ mFragment = fragment;
mIconRes = iconRes;
+ mFragmentController = fragmentController;
}
@Override
@@ -59,8 +57,7 @@
@Override
public void onClick() {
- Intent intent = new Intent(mContext, mActivityClass);
- mContext.startActivity(intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(mFragment);
}
@Override
diff --git a/src/com/android/car/settings/common/TextLineItem.java b/src/com/android/car/settings/common/TextLineItem.java
index 95366e0..f1227e9 100644
--- a/src/com/android/car/settings/common/TextLineItem.java
+++ b/src/com/android/car/settings/common/TextLineItem.java
@@ -27,9 +27,9 @@
* Contains logic for a line item represents text only view of a title and a description.
*/
public abstract class TextLineItem extends TypedPagedListAdapter.LineItem<TextLineItem.ViewHolder> {
- private final CharSequence mTitle;
+ protected final CharSequence mTitle;
- private View.OnClickListener mOnClickListener = (v) -> onClick();
+ protected View.OnClickListener mOnClickListener = (v) -> onClick();
public TextLineItem(CharSequence title) {
mTitle = title;
@@ -48,9 +48,9 @@
viewHolder.itemView.setEnabled(isEnabled());
}
- static class ViewHolder extends RecyclerView.ViewHolder {
- final TextView titleView;
- final TextView descView;
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+ public final TextView titleView;
+ public final TextView descView;
public ViewHolder(View view) {
super(view);
diff --git a/src/com/android/car/settings/common/TypedPagedListAdapter.java b/src/com/android/car/settings/common/TypedPagedListAdapter.java
index 69188aa..c92625f 100644
--- a/src/com/android/car/settings/common/TypedPagedListAdapter.java
+++ b/src/com/android/car/settings/common/TypedPagedListAdapter.java
@@ -40,13 +40,23 @@
private static final String TAG = "TypedPagedListAdapter";
private final Context mContext;
- private final ArrayList<? extends LineItem> mContentList;
+ private ArrayList<? extends LineItem> mContentList;
- public TypedPagedListAdapter(@NonNull Context context, ArrayList<? extends LineItem> contentList) {
+ public TypedPagedListAdapter(@NonNull Context context) {
+ this(context, new ArrayList<>());
+ }
+
+ public TypedPagedListAdapter(
+ @NonNull Context context, ArrayList<? extends LineItem> contentList) {
mContext = context;
mContentList = contentList;
}
+ public void updateList(ArrayList<? extends LineItem> contentList) {
+ mContentList = contentList;
+ notifyDataSetChanged();
+ }
+
public boolean isEmpty() {
return mContentList.isEmpty();
}
diff --git a/src/com/android/car/settings/datetime/DatePickerActivity.java b/src/com/android/car/settings/datetime/DatePickerActivity.java
deleted file mode 100644
index 33b676e..0000000
--- a/src/com/android/car/settings/datetime/DatePickerActivity.java
+++ /dev/null
@@ -1,59 +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.datetime;
-
-import android.app.AlarmManager;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.widget.DatePicker;
-
-import com.android.car.settings.common.CarSettingActivity;
-import com.android.car.settings.R;
-
-import java.util.Calendar;
-
-/**
- * Sets the system date.
- */
-public class DatePickerActivity extends CarSettingActivity {
- private static final int MILLIS_IN_SECOND = 1000;
-
- private DatePicker mDatePicker;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.date_picker);
-
- mDatePicker = (DatePicker) findViewById(R.id.date_picker);
-
- findViewById(R.id.confirm).setOnClickListener(v -> {
- Calendar c = Calendar.getInstance();
-
- c.set(Calendar.YEAR, mDatePicker.getYear());
- c.set(Calendar.MONTH, mDatePicker.getMonth());
- c.set(Calendar.DAY_OF_MONTH, mDatePicker.getDayOfMonth());
- long when = Math.max(c.getTimeInMillis(), DatetimeSettingsActivity.MIN_DATE);
- if (when / MILLIS_IN_SECOND < Integer.MAX_VALUE) {
- ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).setTime(when);
- sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
- }
- finish();
- });
- }
-}
diff --git a/src/com/android/car/settings/datetime/DatePickerFragment.java b/src/com/android/car/settings/datetime/DatePickerFragment.java
new file mode 100644
index 0000000..bd2a551
--- /dev/null
+++ b/src/com/android/car/settings/datetime/DatePickerFragment.java
@@ -0,0 +1,70 @@
+/*
+ * 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.datetime;
+
+import android.app.AlarmManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.DatePicker;
+import android.widget.TextView;
+
+import com.android.car.settings.common.BaseFragment;
+import com.android.car.settings.R;
+
+import java.util.Calendar;
+
+/**
+ * Sets the system date.
+ */
+public class DatePickerFragment extends BaseFragment {
+ private static final int MILLIS_IN_SECOND = 1000;
+
+ private DatePicker mDatePicker;
+
+ public static DatePickerFragment getInstance() {
+ DatePickerFragment datePickerFragment = new DatePickerFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.date_picker_title);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.date_picker);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+ datePickerFragment.setArguments(bundle);
+ return datePickerFragment;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ mDatePicker = (DatePicker) getView().findViewById(R.id.date_picker);
+
+ TextView button = (TextView) getActivity().findViewById(R.id.action_button1);
+ button.setText(R.string.okay);
+ button.setOnClickListener(v -> {
+ Calendar c = Calendar.getInstance();
+
+ c.set(Calendar.YEAR, mDatePicker.getYear());
+ c.set(Calendar.MONTH, mDatePicker.getMonth());
+ c.set(Calendar.DAY_OF_MONTH, mDatePicker.getDayOfMonth());
+ long when = Math.max(c.getTimeInMillis(), DatetimeSettingsFragment.MIN_DATE);
+ if (when / MILLIS_IN_SECOND < Integer.MAX_VALUE) {
+ ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setTime(when);
+ getContext().sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
+ }
+ mFragmentController.goBack();
+ });
+ }
+}
diff --git a/src/com/android/car/settings/datetime/DatetimeSettingsActivity.java b/src/com/android/car/settings/datetime/DatetimeSettingsFragment.java
similarity index 65%
rename from src/com/android/car/settings/datetime/DatetimeSettingsActivity.java
rename to src/com/android/car/settings/datetime/DatetimeSettingsFragment.java
index 69143e6..e93dc73 100644
--- a/src/com/android/car/settings/datetime/DatetimeSettingsActivity.java
+++ b/src/com/android/car/settings/datetime/DatetimeSettingsFragment.java
@@ -19,10 +19,11 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.os.Bundle;
import android.provider.Settings;
import com.android.car.settings.R;
-import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.common.ListSettingsFragment;
import com.android.car.settings.common.TypedPagedListAdapter;
import java.util.ArrayList;
@@ -30,8 +31,8 @@
/**
* Configures date time
*/
-public class DatetimeSettingsActivity extends ListSettingsActivity {
- private static final String TAG = "DatetimeSettingsActivity";
+public class DatetimeSettingsFragment extends ListSettingsFragment {
+ private static final String TAG = "DatetimeSettingsFragment";
private static final IntentFilter TIME_CHANGED_FILTER =
new IntentFilter(Intent.ACTION_TIME_CHANGED);
@@ -42,35 +43,43 @@
private final TimeChangedBroadCastReceiver mTimeChangedBroadCastReceiver =
new TimeChangedBroadCastReceiver();
+ public static DatetimeSettingsFragment getInstance() {
+ DatetimeSettingsFragment datetimeSettingsFragment = new DatetimeSettingsFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.date_and_time_settings_title);
+ datetimeSettingsFragment.setArguments(bundle);
+ return datetimeSettingsFragment;
+ }
+
@Override
public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
- lineItems.add(new DateTimeToggleLineItem(this,
+ lineItems.add(new DateTimeToggleLineItem(getContext(),
getString(R.string.date_time_auto),
getString(R.string.date_time_auto_summary),
Settings.Global.AUTO_TIME));
- lineItems.add(new DateTimeToggleLineItem(this,
+ lineItems.add(new DateTimeToggleLineItem(getContext(),
getString(R.string.zone_auto),
getString(R.string.zone_auto_summary),
Settings.Global.AUTO_TIME_ZONE));
- lineItems.add(new SetDateLineItem(this));
- lineItems.add(new SetTimeLineItem(this));
- lineItems.add(new SetTimeZoneLineItem(this));
- lineItems.add(new TimeFormatToggleLineItem(this));
+ lineItems.add(new SetDateLineItem(getContext(), mFragmentController));
+ lineItems.add(new SetTimeLineItem(getContext(), mFragmentController));
+ lineItems.add(new SetTimeZoneLineItem(getContext(), mFragmentController));
+ lineItems.add(new TimeFormatToggleLineItem(getContext()));
return lineItems;
}
@Override
public void onStart() {
super.onStart();
- registerReceiver(mTimeChangedBroadCastReceiver, TIME_CHANGED_FILTER);
+ getActivity().registerReceiver(mTimeChangedBroadCastReceiver, TIME_CHANGED_FILTER);
mPagedListAdapter.notifyDataSetChanged();
}
@Override
public void onStop() {
super.onStop();
- unregisterReceiver(mTimeChangedBroadCastReceiver);
+ getActivity().unregisterReceiver(mTimeChangedBroadCastReceiver);
}
private class TimeChangedBroadCastReceiver extends BroadcastReceiver {
diff --git a/src/com/android/car/settings/datetime/SetDateLineItem.java b/src/com/android/car/settings/datetime/SetDateLineItem.java
index 2f77044..2dfe0e8 100644
--- a/src/com/android/car/settings/datetime/SetDateLineItem.java
+++ b/src/com/android/car/settings/datetime/SetDateLineItem.java
@@ -17,14 +17,12 @@
package com.android.car.settings.datetime;
import android.content.Context;
-import android.content.Intent;
import android.provider.Settings;
import android.text.format.DateFormat;
import com.android.car.settings.R;
-import com.android.car.settings.common.AnimationUtil;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.TextLineItem;
-import com.android.settingslib.datetime.ZoneGetter;
import java.util.Calendar;
@@ -32,12 +30,13 @@
* A LineItem that displays and sets system date.
*/
class SetDateLineItem extends TextLineItem {
+ private final Context mContext;
+ private final BaseFragment.FragmentController mFragmentController;
- private Context mContext;
-
- public SetDateLineItem(Context context) {
+ public SetDateLineItem(Context context, BaseFragment.FragmentController fragmentController) {
super(context.getString(R.string.date_time_set_date));
mContext = context;
+ mFragmentController = fragmentController;
}
@Override
@@ -53,7 +52,6 @@
@Override
public void onClick() {
- Intent intent = new Intent(mContext /* context */, DatePickerActivity.class);
- mContext.startActivity(intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(DatePickerFragment.getInstance());
}
}
diff --git a/src/com/android/car/settings/datetime/SetTimeLineItem.java b/src/com/android/car/settings/datetime/SetTimeLineItem.java
index 25b3944..26fcf67 100644
--- a/src/com/android/car/settings/datetime/SetTimeLineItem.java
+++ b/src/com/android/car/settings/datetime/SetTimeLineItem.java
@@ -17,12 +17,11 @@
package com.android.car.settings.datetime;
import android.content.Context;
-import android.content.Intent;
import android.provider.Settings;
import android.text.format.DateFormat;
import com.android.car.settings.R;
-import com.android.car.settings.common.AnimationUtil;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.TextLineItem;
import com.android.settingslib.datetime.ZoneGetter;
@@ -32,12 +31,13 @@
* A LineItem that displays and sets system time.
*/
class SetTimeLineItem extends TextLineItem {
+ private final Context mContext;
+ private final BaseFragment.FragmentController mFragmentController;
- private Context mContext;
-
- public SetTimeLineItem(Context context) {
+ public SetTimeLineItem(Context context, BaseFragment.FragmentController fragmentController) {
super(context.getString(R.string.date_time_set_time));
mContext = context;
+ mFragmentController = fragmentController;
}
@Override
@@ -53,7 +53,6 @@
@Override
public void onClick() {
- Intent intent = new Intent(mContext, TimePickerActivity.class);
- mContext.startActivity(intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(TimePickerFragment.getInstance());
}
}
diff --git a/src/com/android/car/settings/datetime/SetTimeZoneLineItem.java b/src/com/android/car/settings/datetime/SetTimeZoneLineItem.java
index c67b2a6..3e23c27 100644
--- a/src/com/android/car/settings/datetime/SetTimeZoneLineItem.java
+++ b/src/com/android/car/settings/datetime/SetTimeZoneLineItem.java
@@ -17,11 +17,10 @@
package com.android.car.settings.datetime;
import android.content.Context;
-import android.content.Intent;
import android.provider.Settings;
import com.android.car.settings.R;
-import com.android.car.settings.common.AnimationUtil;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.TextLineItem;
import com.android.settingslib.datetime.ZoneGetter;
@@ -31,12 +30,13 @@
* A LineItem that displays and sets time zone.
*/
class SetTimeZoneLineItem extends TextLineItem {
+ private final Context mContext;
+ private final BaseFragment.FragmentController mFragmentController;
- private Context mContext;
-
- public SetTimeZoneLineItem(Context context) {
+ public SetTimeZoneLineItem(Context context, BaseFragment.FragmentController fragmentController) {
super(context.getString(R.string.date_time_set_timezone));
mContext = context;
+ mFragmentController = fragmentController;
}
@Override
@@ -53,7 +53,6 @@
@Override
public void onClick() {
- Intent intent = new Intent(mContext, TimeZonePickerActivity.class);
- mContext.startActivity(intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(TimeZonePickerFragment.getInstance());
}
}
diff --git a/src/com/android/car/settings/datetime/TimePickerActivity.java b/src/com/android/car/settings/datetime/TimePickerActivity.java
deleted file mode 100644
index 2e831be..0000000
--- a/src/com/android/car/settings/datetime/TimePickerActivity.java
+++ /dev/null
@@ -1,61 +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.datetime;
-
-import android.app.AlarmManager;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.widget.TimePicker;
-
-import com.android.car.settings.common.CarSettingActivity;
-import com.android.car.settings.R;
-
-import java.util.Calendar;
-
-/**
- * Sets the system time.
- */
-public class TimePickerActivity extends CarSettingActivity {
- private static final int MILLIS_IN_SECOND = 1000;
-
- private TimePicker mTimePicker;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.time_picker);
-
- mTimePicker = (TimePicker) findViewById(R.id.time_picker);
-
- findViewById(R.id.confirm).setOnClickListener(v -> {
- Calendar c = Calendar.getInstance();
-
- c.set(Calendar.HOUR_OF_DAY, mTimePicker.getHour());
- c.set(Calendar.MINUTE, mTimePicker.getMinute());
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- long when = Math.max(c.getTimeInMillis(), DatetimeSettingsActivity.MIN_DATE);
- if (when / MILLIS_IN_SECOND < Integer.MAX_VALUE) {
- ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).setTime(when);
- sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
- }
- finish();
- });
- }
-}
diff --git a/src/com/android/car/settings/datetime/TimePickerFragment.java b/src/com/android/car/settings/datetime/TimePickerFragment.java
new file mode 100644
index 0000000..5179f76
--- /dev/null
+++ b/src/com/android/car/settings/datetime/TimePickerFragment.java
@@ -0,0 +1,72 @@
+/*
+ * 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.datetime;
+
+import android.app.AlarmManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.TextView;
+import android.widget.TimePicker;
+
+import com.android.car.settings.common.BaseFragment;
+import com.android.car.settings.R;
+
+import java.util.Calendar;
+
+/**
+ * Sets the system time.
+ */
+public class TimePickerFragment extends BaseFragment {
+ private static final int MILLIS_IN_SECOND = 1000;
+
+ private TimePicker mTimePicker;
+
+ public static TimePickerFragment getInstance() {
+ TimePickerFragment timePickerFragment = new TimePickerFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.time_picker_title);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.time_picker);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+ timePickerFragment.setArguments(bundle);
+ return timePickerFragment;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ mTimePicker = (TimePicker) getView().findViewById(R.id.time_picker);
+
+ TextView button = (TextView) getActivity().findViewById(R.id.action_button1);
+ button.setText(R.string.okay);
+ button.setOnClickListener(v -> {
+ Calendar c = Calendar.getInstance();
+
+ c.set(Calendar.HOUR_OF_DAY, mTimePicker.getHour());
+ c.set(Calendar.MINUTE, mTimePicker.getMinute());
+ c.set(Calendar.SECOND, 0);
+ c.set(Calendar.MILLISECOND, 0);
+ long when = Math.max(c.getTimeInMillis(), DatetimeSettingsFragment.MIN_DATE);
+ if (when / MILLIS_IN_SECOND < Integer.MAX_VALUE) {
+ ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setTime(when);
+ getContext().sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
+ }
+ mFragmentController.goBack();
+ });
+ }
+}
diff --git a/src/com/android/car/settings/datetime/TimeZonePickerActivity.java b/src/com/android/car/settings/datetime/TimeZonePickerActivity.java
deleted file mode 100644
index e94b200..0000000
--- a/src/com/android/car/settings/datetime/TimeZonePickerActivity.java
+++ /dev/null
@@ -1,51 +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.datetime;
-
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.support.v7.widget.RecyclerView;
-import com.android.car.settings.common.CarSettingActivity;
-import com.android.car.settings.R;
-import com.android.car.view.PagedListView;
-
-/**
- * Lists all time zone and its offset from GMT.
- */
-public class TimeZonePickerActivity extends CarSettingActivity implements
- TimeZoneListAdapter.TimeZoneChangeListener {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.list);
-
- PagedListView listView = (PagedListView) findViewById(android.R.id.list);
- listView.setDefaultItemDecoration(new PagedListView.Decoration(this /* context */));
- listView.setDarkMode();
- TimeZoneListAdapter adapter = new TimeZoneListAdapter(
- this /* context */, this /* TimeZoneChangeListener */);
- listView.setAdapter(adapter);
- }
-
- @Override
- public void onTimeZoneChanged() {
- sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
- finish();
- }
-}
diff --git a/src/com/android/car/settings/datetime/TimeZonePickerFragment.java b/src/com/android/car/settings/datetime/TimeZonePickerFragment.java
new file mode 100644
index 0000000..846d665
--- /dev/null
+++ b/src/com/android/car/settings/datetime/TimeZonePickerFragment.java
@@ -0,0 +1,60 @@
+/*
+ * 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.datetime;
+
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v7.widget.RecyclerView;
+
+import com.android.car.settings.common.BaseFragment;
+import com.android.car.settings.R;
+import com.android.car.view.PagedListView;
+
+/**
+ * Lists all time zone and its offset from GMT.
+ */
+public class TimeZonePickerFragment extends BaseFragment implements
+ TimeZoneListAdapter.TimeZoneChangeListener {
+
+ public static TimeZonePickerFragment getInstance() {
+ TimeZonePickerFragment timeZonePickerFragment = new TimeZonePickerFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.date_time_set_timezone_title);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.list);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar);
+ timeZonePickerFragment.setArguments(bundle);
+ return timeZonePickerFragment;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ PagedListView listView = (PagedListView) getView().findViewById(R.id.list);
+ listView.setDefaultItemDecoration(new PagedListView.Decoration(getContext()));
+ listView.setDarkMode();
+ TimeZoneListAdapter adapter = new TimeZoneListAdapter(
+ getContext(), this /* TimeZoneChangeListener */);
+ listView.setAdapter(adapter);
+ }
+
+ @Override
+ public void onTimeZoneChanged() {
+ getContext().sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
+ mFragmentController.goBack();
+ }
+}
diff --git a/src/com/android/car/settings/display/DisplaySettingsActivity.java b/src/com/android/car/settings/display/DisplaySettingsFragment.java
similarity index 61%
rename from src/com/android/car/settings/display/DisplaySettingsActivity.java
rename to src/com/android/car/settings/display/DisplaySettingsFragment.java
index 596e8ab..3bff828 100644
--- a/src/com/android/car/settings/display/DisplaySettingsActivity.java
+++ b/src/com/android/car/settings/display/DisplaySettingsFragment.java
@@ -15,8 +15,10 @@
*/
package com.android.car.settings.display;
+import android.os.Bundle;
+
import com.android.car.settings.R;
-import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.common.ListSettingsFragment;
import com.android.car.settings.common.TypedPagedListAdapter;
import java.util.ArrayList;
@@ -24,13 +26,21 @@
/**
* Activity to host Display related preferences.
*/
-public class DisplaySettingsActivity extends ListSettingsActivity {
+public class DisplaySettingsFragment extends ListSettingsFragment {
+
+ public static DisplaySettingsFragment getInstance() {
+ DisplaySettingsFragment displaySettingsFragment = new DisplaySettingsFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.display_settings);
+ displaySettingsFragment.setArguments(bundle);
+ return displaySettingsFragment;
+ }
@Override
public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
- lineItems.add(new AutoBrightnessLineItem(this /* context */));
- lineItems.add(new BrightnessLineItem(this /* context */));
+ lineItems.add(new AutoBrightnessLineItem(getContext()));
+ lineItems.add(new BrightnessLineItem(getContext()));
return lineItems;
}
}
diff --git a/src/com/android/car/settings/home/BluetoothLineItem.java b/src/com/android/car/settings/home/BluetoothLineItem.java
index d5026f4..1c35798 100644
--- a/src/com/android/car/settings/home/BluetoothLineItem.java
+++ b/src/com/android/car/settings/home/BluetoothLineItem.java
@@ -20,11 +20,10 @@
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.AnimationUtil;
+import com.android.car.settings.bluetooth.BluetoothSettingsFragment;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.IconToggleLineItem;
@@ -33,9 +32,11 @@
*/
public class BluetoothLineItem extends IconToggleLineItem {
private BluetoothAdapter mBluetoothAdapter;
+ private BaseFragment.FragmentController mFragmentController;
- public BluetoothLineItem(Context context) {
+ public BluetoothLineItem(Context context, BaseFragment.FragmentController fragmentController) {
super(context.getText(R.string.bluetooth_settings), context);
+ mFragmentController = fragmentController;
mBluetoothAdapter =
((BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter();
@@ -52,8 +53,7 @@
@Override
public void onClicked() {
- Intent intent = new Intent(mContext, BluetoothSettingsActivity.class);
- mContext.startActivity(intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(BluetoothSettingsFragment.getInstance());
}
@Override
diff --git a/src/com/android/car/settings/home/HomepageActivity.java b/src/com/android/car/settings/home/HomepageFragment.java
similarity index 66%
rename from src/com/android/car/settings/home/HomepageActivity.java
rename to src/com/android/car/settings/home/HomepageFragment.java
index 7891c9a..d990237 100644
--- a/src/com/android/car/settings/home/HomepageActivity.java
+++ b/src/com/android/car/settings/home/HomepageFragment.java
@@ -22,16 +22,17 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
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.applications.ApplicationSettingsFragment;
+import com.android.car.settings.common.ListSettingsFragment;
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.datetime.DatetimeSettingsFragment;
+import com.android.car.settings.display.DisplaySettingsFragment;
+import com.android.car.settings.sound.SoundSettingsFragment;
+import com.android.car.settings.system.SystemSettingsFragment;
import com.android.car.settings.wifi.CarWifiManager;
import java.util.ArrayList;
@@ -39,7 +40,7 @@
/**
* Homepage for settings for car.
*/
-public class HomepageActivity extends ListSettingsActivity implements CarWifiManager.Listener {
+public class HomepageFragment extends ListSettingsFragment implements CarWifiManager.Listener {
private CarWifiManager mCarWifiManager;
private WifiLineItem mWifiLineItem;
private BluetoothLineItem mBluetoothLineItem;
@@ -67,15 +68,24 @@
private final IntentFilter mBtStateChangeFilter =
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
+ public static HomepageFragment getInstance() {
+ HomepageFragment homepageFragment = new HomepageFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.settings_label);
+ homepageFragment.setArguments(bundle);
+ return homepageFragment;
+ }
+
@Override
- protected void onCreate(Bundle savedInstanceState) {
- mCarWifiManager = new CarWifiManager(this /* context */ , this /* listener */);
- mWifiLineItem = new WifiLineItem(this, mCarWifiManager);
- mBluetoothLineItem = new BluetoothLineItem(this);
+ public void onActivityCreated(Bundle savedInstanceState) {
+ mCarWifiManager = new CarWifiManager(getContext(), this /* listener */);
+ mWifiLineItem = new WifiLineItem(getContext(), mCarWifiManager, mFragmentController);
+ mBluetoothLineItem = new BluetoothLineItem(getContext(), mFragmentController);
// Call super after the wifiLineItem and BluetoothLineItem are setup, because
// those are needed in super.onCreate().
- super.onCreate(savedInstanceState);
+ super.onActivityCreated(savedInstanceState);
+ ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
@Override
@@ -92,14 +102,14 @@
public void onStart() {
super.onStart();
mCarWifiManager.start();
- registerReceiver(mBtStateReceiver, mBtStateChangeFilter);
+ getActivity().registerReceiver(mBtStateReceiver, mBtStateChangeFilter);
}
@Override
public void onStop() {
super.onStop();
mCarWifiManager.stop();
- unregisterReceiver(mBtStateReceiver);
+ getActivity().unregisterReceiver(mBtStateReceiver);
}
@Override
@@ -108,40 +118,40 @@
lineItems.add(new SimpleIconLineItem(
R.string.display_settings,
R.drawable.ic_settings_display,
- this,
+ getContext(),
null,
- DisplaySettingsActivity.class));
+ DisplaySettingsFragment.getInstance(),
+ mFragmentController));
lineItems.add(new SimpleIconLineItem(
R.string.sound_settings,
R.drawable.ic_settings_sound,
- this,
+ getContext(),
null,
- SoundSettingsActivity.class));
+ SoundSettingsFragment.getInstance(),
+ mFragmentController));
lineItems.add(mWifiLineItem);
lineItems.add(mBluetoothLineItem);
lineItems.add(new SimpleIconLineItem(
R.string.applications_settings,
R.drawable.ic_settings_applications,
- this,
+ getContext(),
null,
- ApplicationSettingsActivity.class));
+ ApplicationSettingsFragment.getInstance(),
+ mFragmentController));
lineItems.add(new SimpleIconLineItem(
R.string.date_and_time_settings_title,
R.drawable.ic_settings_date_time,
- this,
+ getContext(),
null,
- DatetimeSettingsActivity.class));
+ DatetimeSettingsFragment.getInstance(),
+ mFragmentController));
lineItems.add(new SimpleIconLineItem(
R.string.system_setting_title,
R.drawable.ic_settings_about,
- this,
+ getContext(),
null,
- SystemSettingsActivity.class));
+ SystemSettingsFragment.getInstance(),
+ mFragmentController));
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
index b6a1c82..1bc1a05 100644
--- a/src/com/android/car/settings/home/WifiLineItem.java
+++ b/src/com/android/car/settings/home/WifiLineItem.java
@@ -19,14 +19,13 @@
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.AnimationUtil;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.IconToggleLineItem;
import com.android.car.settings.wifi.CarWifiManager;
-import com.android.car.settings.wifi.WifiSettingsActivity;
+import com.android.car.settings.wifi.WifiSettingsFragment;
/**
@@ -35,11 +34,16 @@
public class WifiLineItem extends IconToggleLineItem {
private final Context mContext;
private final CarWifiManager mCarWifiManager;
+ private BaseFragment.FragmentController mFragmentController;
- public WifiLineItem(Context context, CarWifiManager carWifiManager) {
+ public WifiLineItem(
+ Context context,
+ CarWifiManager carWifiManager,
+ BaseFragment.FragmentController fragmentController) {
super(context.getText(R.string.wifi_settings), context);
mContext = context;
mCarWifiManager = carWifiManager;
+ mFragmentController = fragmentController;
}
@Override
@@ -49,8 +53,7 @@
@Override
public void onClicked() {
- Intent intent = new Intent(mContext, WifiSettingsActivity.class);
- mContext.startActivity(intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(WifiSettingsFragment.getInstance());
}
@Override
diff --git a/src/com/android/car/settings/sound/SoundSettingsActivity.java b/src/com/android/car/settings/sound/SoundSettingsFragment.java
similarity index 72%
rename from src/com/android/car/settings/sound/SoundSettingsActivity.java
rename to src/com/android/car/settings/sound/SoundSettingsFragment.java
index 2c98f5b..6094224 100644
--- a/src/com/android/car/settings/sound/SoundSettingsActivity.java
+++ b/src/com/android/car/settings/sound/SoundSettingsFragment.java
@@ -28,7 +28,7 @@
import android.os.RemoteException;
import android.util.Log;
-import com.android.car.settings.common.CarSettingActivity;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.TypedPagedListAdapter;
import com.android.car.settings.R;
import com.android.car.view.PagedListView;
@@ -38,16 +38,16 @@
/**
* Activity hosts sound related settings.
*/
-public class SoundSettingsActivity extends CarSettingActivity {
- private static final String TAG = "SoundSettingsActivity";
+public class SoundSettingsFragment extends BaseFragment {
+ private static final String TAG = "SoundSettingsFragment";
private Car mCar;
private CarAudioManager mCarAudioManager;
private PagedListView mListView;
private TypedPagedListAdapter mPagedListAdapter;
private final ArrayList<VolumeLineItem> mVolumeLineItems = new ArrayList<>();
- private final SoundSettingsActivity.VolumnCallback
- mVolumeCallback = new SoundSettingsActivity.VolumnCallback();
+ private final SoundSettingsFragment.VolumnCallback
+ mVolumeCallback = new SoundSettingsFragment.VolumnCallback();
private final ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
@@ -62,31 +62,28 @@
Log.e(TAG, "Car is not connected!", e);
return;
}
- mListView = (PagedListView) findViewById(R.id.list);
- mListView.setDefaultItemDecoration(
- new PagedListView.Decoration(SoundSettingsActivity.this));
- mListView.setDarkMode();
mVolumeLineItems.add(new VolumeLineItem(
- SoundSettingsActivity.this,
+ getContext(),
mCarAudioManager,
AudioManager.STREAM_MUSIC,
R.string.media_volume_title,
com.android.internal.R.drawable.ic_audio_media));
mVolumeLineItems.add(new VolumeLineItem(
- SoundSettingsActivity.this,
+ getContext(),
mCarAudioManager,
AudioManager.STREAM_RING,
R.string.ring_volume_title,
com.android.internal.R.drawable.ic_audio_ring_notif));
mVolumeLineItems.add(new VolumeLineItem(
- SoundSettingsActivity.this,
+ getContext(),
mCarAudioManager,
naviAudioAttributes.getVolumeControlStream(),
R.string.navi_volume_title,
R.drawable.ic_audio_navi));
- mPagedListAdapter = new TypedPagedListAdapter(
- SoundSettingsActivity.this /* context */, mVolumeLineItems);
- mListView.setAdapter(mPagedListAdapter);
+ // if list is already initiated, update it's content.
+ if (mPagedListAdapter != null) {
+ mPagedListAdapter.updateList(mVolumeLineItems);
+ }
}
@Override
@@ -95,11 +92,34 @@
}
};
+ public static SoundSettingsFragment getInstance() {
+ SoundSettingsFragment soundSettingsFragment = new SoundSettingsFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.sound_settings);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.list);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar);
+ soundSettingsFragment.setArguments(bundle);
+ return soundSettingsFragment;
+ }
+
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.list);
- mCar = Car.createCar(this /* context */, mServiceConnection);
+ mCar = Car.createCar(getContext(), mServiceConnection);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mListView = (PagedListView) getView().findViewById(R.id.list);
+ mListView.setDefaultItemDecoration(
+ new PagedListView.Decoration(getContext()));
+ mListView.setDarkMode();
+ mPagedListAdapter = new TypedPagedListAdapter(getContext());
+ mListView.setAdapter(mPagedListAdapter);
+ if (!mVolumeLineItems.isEmpty()) {
+ mPagedListAdapter.updateList(mVolumeLineItems);
+ }
}
@Override
diff --git a/src/com/android/car/settings/system/AboutSettingsActivity.java b/src/com/android/car/settings/system/AboutSettingsFragment.java
similarity index 78%
rename from src/com/android/car/settings/system/AboutSettingsActivity.java
rename to src/com/android/car/settings/system/AboutSettingsFragment.java
index 8f630f7..a4976a2 100644
--- a/src/com/android/car/settings/system/AboutSettingsActivity.java
+++ b/src/com/android/car/settings/system/AboutSettingsFragment.java
@@ -17,8 +17,9 @@
package com.android.car.settings.system;
import android.os.Build;
+import android.os.Bundle;
-import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.common.ListSettingsFragment;
import com.android.car.settings.common.NoDividerItemDecoration;
import com.android.car.settings.common.SimpleTextLineItem;
import com.android.car.settings.common.TypedPagedListAdapter;
@@ -31,7 +32,15 @@
/**
* Shows basic info about the system and provide some actions like update, reset etc.
*/
-public class AboutSettingsActivity extends ListSettingsActivity {
+public class AboutSettingsFragment extends ListSettingsFragment {
+
+ public static AboutSettingsFragment getInstance() {
+ AboutSettingsFragment aboutSettingsFragment = new AboutSettingsFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.about_settings);
+ aboutSettingsFragment.setArguments(bundle);
+ return aboutSettingsFragment;
+ }
@Override
public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
@@ -52,6 +61,6 @@
@Override
public PagedListView.Decoration getDecoration() {
- return new NoDividerItemDecoration(this);
+ return new NoDividerItemDecoration(getContext());
}
}
diff --git a/src/com/android/car/settings/system/AboutSystemLineItem.java b/src/com/android/car/settings/system/AboutSystemLineItem.java
index 2d240de..f8c4537 100644
--- a/src/com/android/car/settings/system/AboutSystemLineItem.java
+++ b/src/com/android/car/settings/system/AboutSystemLineItem.java
@@ -17,12 +17,11 @@
package com.android.car.settings.system;
import android.content.Context;
-import android.content.Intent;
import android.os.Build;
import android.widget.ImageView;
import com.android.car.settings.R;
-import com.android.car.settings.common.AnimationUtil;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.common.IconTextLineItem;
@@ -30,12 +29,13 @@
* A LineItem that displays info about system.
*/
class AboutSystemLineItem extends IconTextLineItem {
-
private final Context mContext;
+ private final BaseFragment.FragmentController mFragmentController;
- public AboutSystemLineItem(Context context) {
+ public AboutSystemLineItem(Context context, BaseFragment.FragmentController fragmentController) {
super(context.getString(R.string.about_settings));
mContext = context;
+ mFragmentController = fragmentController;
}
@Override
@@ -50,8 +50,7 @@
@Override
public void onClick() {
- Intent intent = new Intent(mContext, AboutSettingsActivity.class);
- mContext.startActivity(intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(AboutSettingsFragment.getInstance());
}
@Override
diff --git a/src/com/android/car/settings/system/SystemSettingsActivity.java b/src/com/android/car/settings/system/SystemSettingsActivity.java
deleted file mode 100644
index 37d1614..0000000
--- a/src/com/android/car/settings/system/SystemSettingsActivity.java
+++ /dev/null
@@ -1,38 +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.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/SystemSettingsFragment.java b/src/com/android/car/settings/system/SystemSettingsFragment.java
new file mode 100644
index 0000000..0e3a68c
--- /dev/null
+++ b/src/com/android/car/settings/system/SystemSettingsFragment.java
@@ -0,0 +1,48 @@
+/*
+ * 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.Bundle;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.ListSettingsFragment;
+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 SystemSettingsFragment extends ListSettingsFragment {
+
+ public static SystemSettingsFragment getInstance() {
+ SystemSettingsFragment systemSettingsFragment = new SystemSettingsFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.system_setting_title);
+ systemSettingsFragment.setArguments(bundle);
+ return systemSettingsFragment;
+ }
+
+ @Override
+ public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
+ ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
+ lineItems.add(new SystemUpdatesLineItem(getContext()));
+ lineItems.add(new AboutSystemLineItem(getContext(), mFragmentController));
+ lineItems.add(new LegalInfoLineItem(getContext()));
+ return lineItems;
+ }
+}
diff --git a/src/com/android/car/settings/wifi/AccessPointListAdapter.java b/src/com/android/car/settings/wifi/AccessPointListAdapter.java
index 17d19d1..869df46 100644
--- a/src/com/android/car/settings/wifi/AccessPointListAdapter.java
+++ b/src/com/android/car/settings/wifi/AccessPointListAdapter.java
@@ -16,11 +16,9 @@
package com.android.car.settings.wifi;
import android.content.Context;
-import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.wifi.WifiManager;
-import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@@ -33,7 +31,7 @@
import android.widget.Toast;
import com.android.car.settings.R;
-import com.android.car.settings.common.AnimationUtil;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.view.PagedListView;
import com.android.settingslib.wifi.AccessPoint;
@@ -57,14 +55,19 @@
private final StateListDrawable mWifiSld;
private final Context mContext;
+ private final BaseFragment.FragmentController mFragmentController;
private final CarWifiManager mCarWifiManager;
private final WifiManager.ActionListener mConnectionListener;
private List<AccessPoint> mAccessPoints;
- public AccessPointListAdapter(@NonNull Context context, CarWifiManager carWifiManager,
- @NonNull List<AccessPoint> accesssPoints) {
+ public AccessPointListAdapter(
+ @NonNull Context context,
+ CarWifiManager carWifiManager,
+ @NonNull List<AccessPoint> accesssPoints,
+ BaseFragment.FragmentController fragmentController) {
mContext = context;
+ mFragmentController = fragmentController;
mCarWifiManager = carWifiManager;
mAccessPoints = accesssPoints;
mWifiSld = (StateListDrawable) context.getTheme()
@@ -94,6 +97,7 @@
public class ViewHolder extends RecyclerView.ViewHolder {
private final ImageView mIcon;
+ private final ImageView mRightChevron;
private final TextView mWifiName;
private final TextView mWifiDesc;
@@ -102,6 +106,7 @@
mWifiName = (TextView) view.findViewById(R.id.title);
mWifiDesc = (TextView) view.findViewById(R.id.desc);
mIcon = (ImageView) view.findViewById(R.id.icon);
+ mRightChevron = (ImageView) view.findViewById(R.id.right_chevron);
}
}
@@ -118,15 +123,10 @@
if (mAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE &&
!mAccessPoint.isSaved() && !mAccessPoint.isActive()) {
mCarWifiManager.connectToPublicWifi(mAccessPoint, mConnectionListener);
+ } else if (mAccessPoint.isSaved()) {
+ mFragmentController.launchFragment(WifiDetailFragment.getInstance(mAccessPoint));
} else {
- Intent intent = mAccessPoint.isSaved()
- ? new Intent(mContext , WifiDetailActivity.class)
- : new Intent(mContext, AddWifiActivity.class);
- Bundle accessPointState = new Bundle();
- mAccessPoint.saveWifiState(accessPointState);
- intent.putExtras(accessPointState);
- mContext.startActivity(
- intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(AddWifiFragment.getInstance(mAccessPoint));
}
}
};
@@ -150,10 +150,7 @@
viewHolder.mWifiDesc.setVisibility(View.GONE);
viewHolder.mWifiName.setText(R.string.wifi_setup_add_network);
viewHolder.itemView.setOnClickListener(v -> {
- Intent intent = new Intent(mContext, AddWifiActivity.class);
- intent.putExtra(AddWifiActivity.ADD_NETWORK_MODE, true);
- mContext.startActivity(
- intent, AnimationUtil.slideInFromRightOption(mContext).toBundle());
+ mFragmentController.launchFragment(AddWifiFragment.getInstance(null));
});
}
return viewHolder;
@@ -176,6 +173,12 @@
} else {
holder.mWifiDesc.setVisibility(View.GONE);
}
+ if (accessPoint.getSecurity() == accessPoint.SECURITY_NONE &&
+ !accessPoint.isSaved() && !accessPoint.isActive()) {
+ holder.mRightChevron.setVisibility(View.GONE);
+ } else {
+ holder.mRightChevron.setVisibility(View.VISIBLE);
+ }
}
@Override
diff --git a/src/com/android/car/settings/wifi/AddWifiActivity.java b/src/com/android/car/settings/wifi/AddWifiActivity.java
deleted file mode 100644
index d36400a..0000000
--- a/src/com/android/car/settings/wifi/AddWifiActivity.java
+++ /dev/null
@@ -1,159 +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.wifi;
-
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
-import android.os.Bundle;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.TextView;
-import android.widget.Toast;
-import android.widget.ViewSwitcher;
-
-import com.android.car.settings.common.CarSettingActivity;
-import com.android.car.settings.R;
-import com.android.settingslib.wifi.AccessPoint;
-
-import java.util.regex.Pattern;
-
-/**
- * Adds a wifi network, the network can be public or private. If ADD_NETWORK_MODE is not specified
- * in the intent, then it needs to contain AccessPoint information, which is be use that to
- * render UI, e.g. show SSID etc.
- */
-public class AddWifiActivity extends CarSettingActivity {
- public static final String ADD_NETWORK_MODE = "addNetworkMode";
- private static final String TAG = "AddWifiActivity";
- private static final Pattern HEX_PATTERN = Pattern.compile("^[0-9A-F]+$");
- private AccessPoint mAccessPoint;
- private WifiManager mWifiManager;
- private final WifiManager.ActionListener mConnectionListener = new WifiManager.ActionListener() {
- @Override
- public void onSuccess() {
- }
-
- @Override
- public void onFailure(int reason) {
- Toast.makeText(AddWifiActivity.this,
- R.string.wifi_failed_connect_message,
- Toast.LENGTH_SHORT).show();
- }
- };
- // Switch between display a ssid and entering ssid.
- private ViewSwitcher mSSidViewSwitcher;
- private TextView mWifiNameDisplay;
- private EditText mWifiNameInput;
- private boolean mAddNetworkMode;
- private EditText mWifiPasswordInput;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mWifiManager = (WifiManager) getSystemService(WifiManager.class);
-
- setContentView(R.layout.add_wifi);
- mSSidViewSwitcher = (ViewSwitcher) findViewById(R.id.wifi_name);
- mWifiNameDisplay = (TextView) findViewById(R.id.wifi_name_display);
- mWifiNameInput = (EditText) findViewById(R.id.wifi_name_input);
- mWifiPasswordInput = (EditText) findViewById(R.id.wifi_password);
- Button addWifiButton = (Button) findViewById(R.id.wifi_connect);
- bootstrap();
-
- addWifiButton.setOnClickListener(v -> {
- WifiConfiguration wifiConfig = new WifiConfiguration();
- wifiConfig.SSID = String.format("\"%s\"", getSsId());
- wifiConfig.preSharedKey = String.format(
- "\"%s\"", mWifiPasswordInput.getText().toString());
-
- int netId = mWifiManager.addNetwork(wifiConfig);
- mWifiManager.disconnect();
- mWifiManager.enableNetwork(netId, true);
- mWifiManager.reconnect();
- finish();
- });
- }
-
- private void connectToAccessPoint() {
- WifiConfiguration wifiConfig = new WifiConfiguration();
- wifiConfig.SSID = String.format("\"%s\"", getSsId());
- wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
- wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
- wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
- wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
- wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
- wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
- switch (mAccessPoint.getSecurity()) {
- case AccessPoint.SECURITY_NONE:
- wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- wifiConfig.allowedAuthAlgorithms.clear();
- wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
- wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
- case AccessPoint.SECURITY_WEP:
- wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
- wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
- String password = mWifiPasswordInput.getText().toString();
- wifiConfig.wepKeys[0] = isHexString(password) ? password : "\"" + password + "\"";
- wifiConfig.wepTxKeyIndex = 0;
- case AccessPoint.SECURITY_PSK:
- case AccessPoint.SECURITY_EAP:
- wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
- wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
- wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
- wifiConfig.preSharedKey = String.format(
- "\"%s\"", mWifiPasswordInput.getText().toString());
- }
- int netId = mWifiManager.addNetwork(wifiConfig);
- if (netId != -1) {
- mWifiManager.enableNetwork(netId, true);
- }
- }
-
- private boolean isHexString(String password) {
- return HEX_PATTERN.matcher(password).matches();
- }
-
- // TODO: handle null case, show warning message etc.
- private String getSsId() {
- if (mAddNetworkMode) {
- return mWifiNameInput.getText().toString();
- } else {
- return mAccessPoint.getSsid().toString();
- }
- }
-
- /**
- * Sets up fields based on Intent content, and setup UI accordingly.
- */
- private void bootstrap() {
- Bundle bundle = getIntent().getExtras();
- if (bundle == null) {
- return;
- }
- if (bundle.containsKey(ADD_NETWORK_MODE)) {
- mAddNetworkMode = true;
- } else {
- mAccessPoint = new AccessPoint(this, bundle);
- }
- if (mAddNetworkMode && mSSidViewSwitcher.getCurrentView() == mWifiNameDisplay) {
- mSSidViewSwitcher.showNext();
- }
- if (!mAddNetworkMode) {
- mWifiNameDisplay.setText(mAccessPoint.getSsid());
- }
- }
-}
diff --git a/src/com/android/car/settings/wifi/AddWifiFragment.java b/src/com/android/car/settings/wifi/AddWifiFragment.java
new file mode 100644
index 0000000..1e21753
--- /dev/null
+++ b/src/com/android/car/settings/wifi/AddWifiFragment.java
@@ -0,0 +1,175 @@
+/*
+ * 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.wifi;
+
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.ViewSwitcher;
+
+import com.android.car.settings.common.BaseFragment;
+import com.android.car.settings.R;
+import com.android.settingslib.wifi.AccessPoint;
+
+import java.util.regex.Pattern;
+
+/**
+ * Adds a wifi network, the network can be public or private. If ADD_NETWORK_MODE is not specified
+ * in the intent, then it needs to contain AccessPoint information, which is be use that to
+ * render UI, e.g. show SSID etc.
+ */
+public class AddWifiFragment extends BaseFragment {
+ public static final String EXTRA_AP_STATE = "extra_ap_state";
+
+ private static final String TAG = "AddWifiFragment";
+ private static final Pattern HEX_PATTERN = Pattern.compile("^[0-9A-F]+$");
+ @Nullable private AccessPoint mAccessPoint;
+ private WifiManager mWifiManager;
+ private final WifiManager.ActionListener mConnectionListener =
+ new WifiManager.ActionListener() {
+ @Override
+ public void onSuccess() {
+ }
+
+ @Override
+ public void onFailure(int reason) {
+ Toast.makeText(getContext(),
+ R.string.wifi_failed_connect_message,
+ Toast.LENGTH_SHORT).show();
+ }
+ };
+ // Switch between display a ssid and entering ssid.
+ private ViewSwitcher mSSidViewSwitcher;
+ private TextView mWifiNameDisplay;
+ private EditText mWifiNameInput;
+ private EditText mWifiPasswordInput;
+
+ public static AddWifiFragment getInstance(AccessPoint accessPoint) {
+ AddWifiFragment addWifiFragment = new AddWifiFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.wifi_setup_add_network);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.add_wifi);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar);
+ Bundle accessPointState = new Bundle();
+ if (accessPoint != null) {
+ accessPoint.saveWifiState(accessPointState);
+ bundle.putBundle(EXTRA_AP_STATE, accessPointState);
+ }
+ addWifiFragment.setArguments(bundle);
+ return addWifiFragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getArguments().keySet().contains(EXTRA_AP_STATE)) {
+ mAccessPoint = new AccessPoint(getContext(), getArguments().getBundle(EXTRA_AP_STATE));
+ }
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mWifiManager = getContext().getSystemService(WifiManager.class);
+
+ mSSidViewSwitcher = (ViewSwitcher) getView().findViewById(R.id.wifi_name);
+ mWifiNameDisplay = (TextView) getView().findViewById(R.id.wifi_name_display);
+ mWifiNameInput = (EditText) getView().findViewById(R.id.wifi_name_input);
+ mWifiPasswordInput = (EditText) getView().findViewById(R.id.wifi_password);
+ Button addWifiButton = (Button) getView().findViewById(R.id.wifi_connect);
+ bootstrap();
+
+ addWifiButton.setOnClickListener(v -> {
+ connectToAccessPoint();
+ mFragmentController.goBack();
+ });
+ }
+
+ private void connectToAccessPoint() {
+ WifiConfiguration wifiConfig = new WifiConfiguration();
+ wifiConfig.SSID = String.format("\"%s\"", getSsId());
+ wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
+ wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
+ wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
+ wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
+ if (mAccessPoint == null) {
+ wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
+ wifiConfig.preSharedKey = String.format(
+ "\"%s\"", mWifiPasswordInput.getText().toString());
+ } else {
+ switch (mAccessPoint.getSecurity()) {
+ case AccessPoint.SECURITY_NONE:
+ wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
+ wifiConfig.allowedAuthAlgorithms.clear();
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
+ case AccessPoint.SECURITY_WEP:
+ wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
+ wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
+ wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
+ String password = mWifiPasswordInput.getText().toString();
+ wifiConfig.wepKeys[0] = isHexString(password) ? password
+ : "\"" + password + "\"";
+ wifiConfig.wepTxKeyIndex = 0;
+ case AccessPoint.SECURITY_PSK:
+ case AccessPoint.SECURITY_EAP:
+ wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
+ wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
+ wifiConfig.preSharedKey = String.format(
+ "\"%s\"", mWifiPasswordInput.getText().toString());
+ }
+ }
+ int netId = mWifiManager.addNetwork(wifiConfig);
+ if (netId != -1) {
+ mWifiManager.enableNetwork(netId, true);
+ }
+ }
+
+ private boolean isHexString(String password) {
+ return HEX_PATTERN.matcher(password).matches();
+ }
+
+ // TODO: handle null case, show warning message etc.
+ private String getSsId() {
+ if (mAccessPoint == null) {
+ return mWifiNameInput.getText().toString();
+ } else {
+ return mAccessPoint.getSsid().toString();
+ }
+ }
+
+ /**
+ * Sets up fields based on Intent content, and setup UI accordingly.
+ */
+ private void bootstrap() {
+ if (mAccessPoint == null && mSSidViewSwitcher.getCurrentView() == mWifiNameDisplay) {
+ mSSidViewSwitcher.showNext();
+ }
+ if (mAccessPoint != null) {
+ mWifiNameDisplay.setText(mAccessPoint.getSsid());
+ }
+ }
+}
diff --git a/src/com/android/car/settings/wifi/WifiDetailActivity.java b/src/com/android/car/settings/wifi/WifiDetailFragment.java
similarity index 72%
rename from src/com/android/car/settings/wifi/WifiDetailActivity.java
rename to src/com/android/car/settings/wifi/WifiDetailFragment.java
index 59b312b..d227e75 100644
--- a/src/com/android/car/settings/wifi/WifiDetailActivity.java
+++ b/src/com/android/car/settings/wifi/WifiDetailFragment.java
@@ -19,13 +19,13 @@
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.annotation.StringRes;
+import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
-import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
-import com.android.car.settings.common.ListSettingsActivity;
+import com.android.car.settings.common.ListSettingsFragment;
import com.android.car.settings.common.SimpleTextLineItem;
import com.android.car.settings.common.TypedPagedListAdapter;
import com.android.settingslib.wifi.AccessPoint;
@@ -39,8 +39,10 @@
* e.g. ignore, disconnect, etc. The intent should include information about
* access point, use that to render UI, e.g. show SSID etc.
*/
-public class WifiDetailActivity extends ListSettingsActivity {
- private static final String TAG = "WifiDetailActivity";
+public class WifiDetailFragment extends ListSettingsFragment {
+ public static final String EXTRA_AP_STATE = "extra_ap_state";
+ private static final String TAG = "WifiDetailFragment";
+
private AccessPoint mAccessPoint;
private WifiManager mWifiManager;
@@ -56,41 +58,51 @@
}
@Override
public void onFailure(int reason) {
- Toast.makeText(WifiDetailActivity.this,
+ Toast.makeText(getContext(),
R.string.wifi_failed_connect_message,
Toast.LENGTH_SHORT).show();
}
}
- @Override
- public void setupActionBar() {
- super.setupActionBar();
- getActionBar().setCustomView(R.layout.action_bar_with_button);
- getActionBar().setDisplayShowCustomEnabled(true);
+ public static WifiDetailFragment getInstance(AccessPoint accessPoint) {
+ WifiDetailFragment wifiDetailFragment = new WifiDetailFragment();
+ Bundle bundle = ListSettingsFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.wifi_settings);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+ Bundle accessPointState = new Bundle();
+ accessPoint.saveWifiState(accessPointState);
+ bundle.putBundle(EXTRA_AP_STATE, accessPointState);
+ wifiDetailFragment.setArguments(bundle);
+ return wifiDetailFragment;
}
@Override
- protected void onCreate(Bundle savedInstanceState) {
- mWifiManager = (WifiManager) getSystemService(WifiManager.class);
- mAccessPoint = new AccessPoint(this, getIntent().getExtras());
-
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ((TextView) findViewById(R.id.title)).setText(mAccessPoint.getSsid());
- Button forgetButton = (Button) findViewById(R.id.action_button1);
+ mAccessPoint = new AccessPoint(getContext(), getArguments().getBundle(EXTRA_AP_STATE));
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ mWifiManager = getContext().getSystemService(WifiManager.class);
+
+ super.onActivityCreated(savedInstanceState);
+ ((TextView) getActivity().findViewById(R.id.title)).setText(mAccessPoint.getSsid());
+ TextView forgetButton = (TextView) getActivity().findViewById(R.id.action_button1);
forgetButton.setText(R.string.forget);
forgetButton.setOnClickListener(v -> {
forget();
- finish();
+ mFragmentController.goBack();
});
if (mAccessPoint.isSaved() && !mAccessPoint.isActive()) {
- Button connectButton = (Button) findViewById(R.id.action_button2);
+ TextView connectButton = (TextView) getActivity().findViewById(R.id.action_button2);
connectButton.setVisibility(View.VISIBLE);
connectButton.setText(R.string.wifi_setup_connect);
connectButton.setOnClickListener(v -> {
mWifiManager.connect(mAccessPoint.getConfig(),
new ActionFailListener(R.string.wifi_failed_connect_message));
- finish();
+ mFragmentController.goBack();
});
}
}
diff --git a/src/com/android/car/settings/wifi/WifiSettingsActivity.java b/src/com/android/car/settings/wifi/WifiSettingsFragment.java
similarity index 73%
rename from src/com/android/car/settings/wifi/WifiSettingsActivity.java
rename to src/com/android/car/settings/wifi/WifiSettingsFragment.java
index d7a9064..7021ec6 100644
--- a/src/com/android/car/settings/wifi/WifiSettingsActivity.java
+++ b/src/com/android/car/settings/wifi/WifiSettingsFragment.java
@@ -26,7 +26,7 @@
import android.annotation.StringRes;
-import com.android.car.settings.common.CarSettingActivity;
+import com.android.car.settings.common.BaseFragment;
import com.android.car.settings.R;
import com.android.car.view.PagedListView;
@@ -36,8 +36,8 @@
/**
* Main page to host Wifi related preferences.
*/
-public class WifiSettingsActivity extends CarSettingActivity implements CarWifiManager.Listener {
- private static final String TAG = "WifiSettingsActivity";
+public class WifiSettingsFragment extends BaseFragment implements CarWifiManager.Listener {
+ private static final String TAG = "WifiSettingsFragment";
private CarWifiManager mCarWifiManager;
private AccessPointListAdapter mAdapter;
@@ -47,40 +47,44 @@
private TextView mMessageView;
private ViewSwitcher mViewSwitcher;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mCarWifiManager = new CarWifiManager(this /* context */ , this /* listener */);
- setContentView(R.layout.wifi_list);
+ public static WifiSettingsFragment getInstance() {
+ WifiSettingsFragment wifiSettingsFragment = new WifiSettingsFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_TITLE_ID, R.string.wifi_settings);
+ bundle.putInt(EXTRA_LAYOUT, R.layout.wifi_list);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_toggle);
+ wifiSettingsFragment.setArguments(bundle);
+ return wifiSettingsFragment;
+ }
- ((TextView) findViewById(R.id.title)).setText(R.string.wifi_settings);
- mProgressBar = (ProgressBar) findViewById(R.id.wifi_search_progress);
- mListView = (PagedListView) findViewById(R.id.list);
- mMessageView = (TextView) findViewById(R.id.message);
- mViewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mCarWifiManager = new CarWifiManager(getContext(), this /* listener */);
+
+ mProgressBar = (ProgressBar) getView().findViewById(R.id.wifi_search_progress);
+ mListView = (PagedListView) getView().findViewById(R.id.list);
+ mMessageView = (TextView) getView().findViewById(R.id.message);
+ mViewSwitcher = (ViewSwitcher) getView().findViewById(R.id.view_switcher);
setupWifiSwitch();
if (mCarWifiManager.isWifiEnabled()) {
showList();
} else {
showMessage(R.string.wifi_disabled);
}
- mListView.setDefaultItemDecoration(new PagedListView.Decoration(this));
+ mListView.setDefaultItemDecoration(new PagedListView.Decoration(getContext()));
// Set this to light mode, since the scroll bar buttons always appear
// on top of a dark scrim.
mListView.setDarkMode();
mAdapter = new AccessPointListAdapter(
- this, mCarWifiManager, mCarWifiManager.getAccessPoints());
+ getContext(),
+ mCarWifiManager,
+ mCarWifiManager.getAccessPoints(),
+ mFragmentController);
mListView.setAdapter(mAdapter);
}
@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();
@@ -147,7 +151,7 @@
}
private void setupWifiSwitch() {
- mWifiSwitch = (Switch) findViewById(R.id.toggle_switch);
+ mWifiSwitch = (Switch) getActivity().findViewById(R.id.toggle_switch);
mWifiSwitch.setChecked(mCarWifiManager.isWifiEnabled());
mWifiSwitch.setOnClickListener(v -> {
mCarWifiManager.setWifiEnabled(mWifiSwitch.isChecked());