blob: 4431f3c6a50f682c0817d39b3deb7238246c7a46 [file] [log] [blame]
Michael Kwan246caac2016-05-17 00:46:58 -07001/*
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
17package com.android.internal.app;
18
19import android.content.Context;
20import android.content.DialogInterface;
Michael Kwan55e40302016-07-22 12:17:04 -070021import android.text.TextUtils;
22import android.view.Gravity;
Michael Kwan246caac2016-05-17 00:46:58 -070023import android.view.View;
24import android.view.ViewGroup;
25import android.view.Window;
Michael Kwan55e40302016-07-22 12:17:04 -070026import android.widget.FrameLayout;
27import android.widget.ImageView;
Michael Kwan246caac2016-05-17 00:46:58 -070028import android.widget.ScrollView;
29import android.widget.TextView;
Michael Kwan246caac2016-05-17 00:46:58 -070030
31import com.android.internal.app.AlertController;
32import com.android.internal.R;
33
34public 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 Kwan55e40302016-07-22 12:17:04 -070058 // has ListView, swap scrollView with ListView
Michael Kwan246caac2016-05-17 00:46:58 -070059
Michael Kwan55e40302016-07-22 12:17:04 -070060 // move topPanel into top of scrollParent
Michael Kwan246caac2016-05-17 00:46:58 -070061 View topPanel = mScrollView.findViewById(R.id.topPanel);
62 ((ViewGroup) topPanel.getParent()).removeView(topPanel);
Michael Kwan55e40302016-07-22 12:17:04 -070063 FrameLayout.LayoutParams topParams =
64 new FrameLayout.LayoutParams(topPanel.getLayoutParams());
65 topParams.gravity = Gravity.TOP;
66 topPanel.setLayoutParams(topParams);
Michael Kwan246caac2016-05-17 00:46:58 -070067
Michael Kwan55e40302016-07-22 12:17:04 -070068 // move buttonPanel into bottom of scrollParent
Michael Kwan246caac2016-05-17 00:46:58 -070069 View buttonPanel = mScrollView.findViewById(R.id.buttonPanel);
70 ((ViewGroup) buttonPanel.getParent()).removeView(buttonPanel);
Michael Kwan55e40302016-07-22 12:17:04 -070071 FrameLayout.LayoutParams buttonParams =
72 new FrameLayout.LayoutParams(buttonPanel.getLayoutParams());
73 buttonParams.gravity = Gravity.BOTTOM;
74 buttonPanel.setLayoutParams(buttonParams);
Michael Kwan246caac2016-05-17 00:46:58 -070075
Michael Kwan55e40302016-07-22 12:17:04 -070076 // remove scrollview
Michael Kwan246caac2016-05-17 00:46:58 -070077 final ViewGroup scrollParent = (ViewGroup) mScrollView.getParent();
78 final int childIndex = scrollParent.indexOfChild(mScrollView);
79 scrollParent.removeViewAt(childIndex);
Michael Kwan55e40302016-07-22 12:17:04 -070080
81 // add list view
82 scrollParent.addView(mListView,
Michael Kwan246caac2016-05-17 00:46:58 -070083 new ViewGroup.LayoutParams(
84 ViewGroup.LayoutParams.MATCH_PARENT,
85 ViewGroup.LayoutParams.MATCH_PARENT));
Michael Kwan55e40302016-07-22 12:17:04 -070086
87 // add top and button panel
88 scrollParent.addView(topPanel);
89 scrollParent.addView(buttonPanel);
Michael Kwan246caac2016-05-17 00:46:58 -070090 } else {
91 // no content, just hide everything
92 contentPanel.setVisibility(View.GONE);
93 }
94 }
95 }
Michael Kwan81450812016-07-19 09:48:45 -070096
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 Kwan246caac2016-05-17 00:46:58 -0700112}