Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.app; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.DialogInterface; |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 21 | import android.text.TextUtils; |
| 22 | import android.view.Gravity; |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 23 | import android.view.View; |
| 24 | import android.view.ViewGroup; |
| 25 | import android.view.Window; |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 26 | import android.widget.FrameLayout; |
| 27 | import android.widget.ImageView; |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 28 | import android.widget.ScrollView; |
| 29 | import android.widget.TextView; |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 30 | |
| 31 | import com.android.internal.app.AlertController; |
| 32 | import com.android.internal.R; |
| 33 | |
| 34 | public class MicroAlertController extends AlertController { |
| 35 | public MicroAlertController(Context context, DialogInterface di, Window window) { |
| 36 | super(context, di, window); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | protected void setupContent(ViewGroup contentPanel) { |
| 41 | // Special case for small screen - the scroll view is higher in hierarchy |
| 42 | mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView); |
| 43 | |
| 44 | // Special case for users that only want to display a String |
| 45 | mMessageView = (TextView) contentPanel.findViewById(R.id.message); |
| 46 | if (mMessageView == null) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | if (mMessage != null) { |
| 51 | mMessageView.setText(mMessage); |
| 52 | } else { |
| 53 | // no message, remove associated views |
| 54 | mMessageView.setVisibility(View.GONE); |
| 55 | contentPanel.removeView(mMessageView); |
| 56 | |
| 57 | if (mListView != null) { |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 58 | // has ListView, swap scrollView with ListView |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 59 | |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 60 | // move topPanel into top of scrollParent |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 61 | View topPanel = mScrollView.findViewById(R.id.topPanel); |
| 62 | ((ViewGroup) topPanel.getParent()).removeView(topPanel); |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 63 | FrameLayout.LayoutParams topParams = |
| 64 | new FrameLayout.LayoutParams(topPanel.getLayoutParams()); |
| 65 | topParams.gravity = Gravity.TOP; |
| 66 | topPanel.setLayoutParams(topParams); |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 67 | |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 68 | // move buttonPanel into bottom of scrollParent |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 69 | View buttonPanel = mScrollView.findViewById(R.id.buttonPanel); |
| 70 | ((ViewGroup) buttonPanel.getParent()).removeView(buttonPanel); |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 71 | FrameLayout.LayoutParams buttonParams = |
| 72 | new FrameLayout.LayoutParams(buttonPanel.getLayoutParams()); |
| 73 | buttonParams.gravity = Gravity.BOTTOM; |
| 74 | buttonPanel.setLayoutParams(buttonParams); |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 75 | |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 76 | // remove scrollview |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 77 | final ViewGroup scrollParent = (ViewGroup) mScrollView.getParent(); |
| 78 | final int childIndex = scrollParent.indexOfChild(mScrollView); |
| 79 | scrollParent.removeViewAt(childIndex); |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 80 | |
| 81 | // add list view |
| 82 | scrollParent.addView(mListView, |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 83 | new ViewGroup.LayoutParams( |
| 84 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 85 | ViewGroup.LayoutParams.MATCH_PARENT)); |
Michael Kwan | 55e4030 | 2016-07-22 12:17:04 -0700 | [diff] [blame] | 86 | |
| 87 | // add top and button panel |
| 88 | scrollParent.addView(topPanel); |
| 89 | scrollParent.addView(buttonPanel); |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 90 | } else { |
| 91 | // no content, just hide everything |
| 92 | contentPanel.setVisibility(View.GONE); |
| 93 | } |
| 94 | } |
| 95 | } |
Michael Kwan | 8145081 | 2016-07-19 09:48:45 -0700 | [diff] [blame] | 96 | |
| 97 | @Override |
| 98 | protected void setupTitle(ViewGroup topPanel) { |
| 99 | super.setupTitle(topPanel); |
| 100 | if (topPanel.getVisibility() == View.GONE) { |
| 101 | topPanel.setVisibility(View.INVISIBLE); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | protected void setupButtons(ViewGroup buttonPanel) { |
| 107 | super.setupButtons(buttonPanel); |
| 108 | if (buttonPanel.getVisibility() == View.GONE) { |
| 109 | buttonPanel.setVisibility(View.INVISIBLE); |
| 110 | } |
| 111 | } |
Michael Kwan | 246caac | 2016-05-17 00:46:58 -0700 | [diff] [blame] | 112 | } |