diff options
| author | Michael Kwan <mkwan@google.com> | 2016-05-17 00:46:58 -0700 |
|---|---|---|
| committer | Michael Kwan <mkwan@google.com> | 2016-05-19 17:07:11 -0700 |
| commit | 246caaced5f621077b5f23daf36701f68d03bf3c (patch) | |
| tree | 4aa220262b341bafa06f0a51fbc495bfccc51df2 /core/java | |
| parent | ba15163b2a0821f74691e1df30c56d0fef800e0e (diff) | |
Initial update of Micro theme for Material design.
Bug: 17733928
Change-Id: I7e0ccaa0dd7ee3209c3e517cdfc77dd374b1ce6f
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/app/AlertController.java | 5 | ||||
| -rw-r--r-- | core/java/com/android/internal/app/MicroAlertController.java | 85 |
2 files changed, 90 insertions, 0 deletions
diff --git a/core/java/com/android/internal/app/AlertController.java b/core/java/com/android/internal/app/AlertController.java index 9ade60dcda58..8e101d0823fa 100644 --- a/core/java/com/android/internal/app/AlertController.java +++ b/core/java/com/android/internal/app/AlertController.java @@ -61,6 +61,7 @@ import android.widget.TextView; import java.lang.ref.WeakReference; public class AlertController { + public static final int MICRO = 1; private final Context mContext; private final DialogInterface mDialogInterface; @@ -183,6 +184,8 @@ public class AlertController { a.recycle(); switch (controllerType) { + case MICRO: + return new MicroAlertController(context, di, window); default: return new AlertController(context, di, window); } @@ -1128,6 +1131,7 @@ public class AlertController { listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { + position -= listView.getHeaderViewsCount(); mOnClickListener.onClick(dialog.mDialogInterface, position); if (!mIsSingleChoice) { dialog.mDialogInterface.dismiss(); @@ -1138,6 +1142,7 @@ public class AlertController { listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { + position -= listView.getHeaderViewsCount(); if (mCheckedItems != null) { mCheckedItems[position] = listView.isItemChecked(position); } diff --git a/core/java/com/android/internal/app/MicroAlertController.java b/core/java/com/android/internal/app/MicroAlertController.java new file mode 100644 index 000000000000..085b2265dfee --- /dev/null +++ b/core/java/com/android/internal/app/MicroAlertController.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.app; + +import android.content.Context; +import android.content.DialogInterface; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.ScrollView; +import android.widget.TextView; +import android.widget.AbsListView; + +import com.android.internal.app.AlertController; +import com.android.internal.R; + +public class MicroAlertController extends AlertController { + public MicroAlertController(Context context, DialogInterface di, Window window) { + super(context, di, window); + } + + @Override + protected void setupContent(ViewGroup contentPanel) { + // Special case for small screen - the scroll view is higher in hierarchy + mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView); + + // Special case for users that only want to display a String + mMessageView = (TextView) contentPanel.findViewById(R.id.message); + if (mMessageView == null) { + return; + } + + if (mMessage != null) { + mMessageView.setText(mMessage); + } else { + // no message, remove associated views + mMessageView.setVisibility(View.GONE); + contentPanel.removeView(mMessageView); + + if (mListView != null) { + // has ListView, swap ScrollView with ListView + + // move topPanel into header of ListView + View topPanel = mScrollView.findViewById(R.id.topPanel); + ((ViewGroup) topPanel.getParent()).removeView(topPanel); + topPanel.setLayoutParams( + new AbsListView.LayoutParams(topPanel.getLayoutParams())); + mListView.addHeaderView(topPanel, null, false); + + // move buttonPanel into footer of ListView + View buttonPanel = mScrollView.findViewById(R.id.buttonPanel); + ((ViewGroup) buttonPanel.getParent()).removeView(buttonPanel); + buttonPanel.setLayoutParams( + new AbsListView.LayoutParams(buttonPanel.getLayoutParams())); + mListView.addFooterView(buttonPanel, null, false); + + // swap ScrollView w/ ListView + final ViewGroup scrollParent = (ViewGroup) mScrollView.getParent(); + final int childIndex = scrollParent.indexOfChild(mScrollView); + scrollParent.removeViewAt(childIndex); + scrollParent.addView(mListView, childIndex, + new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + } else { + // no content, just hide everything + contentPanel.setVisibility(View.GONE); + } + } + } +} |
