diff options
3 files changed, 62 insertions, 7 deletions
diff --git a/packages/SettingsLib/res/layout-television/settings_with_drawer.xml b/packages/SettingsLib/res/layout-television/settings_with_drawer.xml new file mode 100644 index 000000000000..e8ca6912e22f --- /dev/null +++ b/packages/SettingsLib/res/layout-television/settings_with_drawer.xml @@ -0,0 +1,20 @@ +<!-- + Copyright (C) 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/content_frame" + android:layout_width="match_parent" + android:layout_height="match_parent" /> diff --git a/packages/SettingsLib/res/layout-watch/settings_with_drawer.xml b/packages/SettingsLib/res/layout-watch/settings_with_drawer.xml new file mode 100644 index 000000000000..e8ca6912e22f --- /dev/null +++ b/packages/SettingsLib/res/layout-watch/settings_with_drawer.xml @@ -0,0 +1,20 @@ +<!-- + Copyright (C) 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/content_frame" + android:layout_width="match_parent" + android:layout_height="match_parent" /> diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java b/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java index 910e6159360c..f5fc6985a892 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java @@ -50,7 +50,9 @@ public class SettingsDrawerActivity extends Activity { requestWindowFeature(Window.FEATURE_NO_TITLE); super.setContentView(R.layout.settings_with_drawer); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - // Nope. + if (mDrawerLayout == null) { + return; + } Toolbar toolbar = (Toolbar) findViewById(R.id.action_bar); setActionBar(toolbar); mDrawerAdapter = new SettingsDrawerAdapter(this); @@ -62,12 +64,12 @@ public class SettingsDrawerActivity extends Activity { onTileClicked(mDrawerAdapter.getTile(position)); }; }); - getActionBar().setHomeAsUpIndicator(R.drawable.ic_menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { + if (mDrawerLayout != null && item.getItemId() == android.R.id.home + && mDrawerAdapter.getCount() != 0) { openDrawer(); return true; } @@ -78,15 +80,19 @@ public class SettingsDrawerActivity extends Activity { protected void onResume() { super.onResume(); - mDrawerAdapter.updateCategories(); + updateDrawer(); } public void openDrawer() { - mDrawerLayout.openDrawer(Gravity.START); + if (mDrawerLayout != null) { + mDrawerLayout.openDrawer(Gravity.START); + } } public void closeDrawer() { - mDrawerLayout.closeDrawers(); + if (mDrawerLayout != null) { + mDrawerLayout.closeDrawers(); + } } @Override @@ -106,9 +112,18 @@ public class SettingsDrawerActivity extends Activity { } public void updateDrawer() { + if (mDrawerLayout == null) { + return; + } // TODO: Do this in the background with some loading. mDrawerAdapter.updateCategories(); - getActionBar().setDisplayHomeAsUpEnabled(mDrawerAdapter.getCount() != 0); + if (mDrawerAdapter.getCount() != 0) { + mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); + getActionBar().setHomeAsUpIndicator(R.drawable.ic_menu); + getActionBar().setDisplayHomeAsUpEnabled(true); + } else { + mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + } } public List<DashboardCategory> getDashboardCategories(boolean force) { |