Merge "Show scroll indicators in AlertDialog" into lmp-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
104504053d
@@ -3229,6 +3229,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
*/
|
*/
|
||||||
private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners;
|
private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners;
|
||||||
|
|
||||||
|
protected OnScrollChangeListener mOnScrollChangeListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listeners for attach events.
|
* Listeners for attach events.
|
||||||
*/
|
*/
|
||||||
@@ -4605,6 +4607,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
return mListenerInfo;
|
return mListenerInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a callback to be invoked when the scroll position of this view
|
||||||
|
* changed.
|
||||||
|
*
|
||||||
|
* @param l The callback that will run.
|
||||||
|
* @hide Only used internally.
|
||||||
|
*/
|
||||||
|
public void setOnScrollChangeListener(OnScrollChangeListener l) {
|
||||||
|
getListenerInfo().mOnScrollChangeListener = l;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a callback to be invoked when focus of this view changed.
|
* Register a callback to be invoked when focus of this view changed.
|
||||||
*
|
*
|
||||||
@@ -9794,6 +9807,29 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
if (ai != null) {
|
if (ai != null) {
|
||||||
ai.mViewScrollChanged = true;
|
ai.mViewScrollChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mListenerInfo != null && mListenerInfo.mOnScrollChangeListener != null) {
|
||||||
|
mListenerInfo.mOnScrollChangeListener.onScrollChange(this, l, t, oldl, oldt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface definition for a callback to be invoked when the scroll
|
||||||
|
* position of a view changes.
|
||||||
|
*
|
||||||
|
* @hide Only used internally.
|
||||||
|
*/
|
||||||
|
public interface OnScrollChangeListener {
|
||||||
|
/**
|
||||||
|
* Called when the scroll position of a view changes.
|
||||||
|
*
|
||||||
|
* @param v The view whose scroll position has changed.
|
||||||
|
* @param scrollX Current horizontal scroll origin.
|
||||||
|
* @param scrollY Current vertical scroll origin.
|
||||||
|
* @param oldScrollX Previous horizontal scroll origin.
|
||||||
|
* @param oldScrollY Previous vertical scroll origin.
|
||||||
|
*/
|
||||||
|
void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -38,9 +37,11 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowInsets;
|
import android.view.WindowInsets;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
@@ -449,11 +450,11 @@ public class AlertController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupView() {
|
private void setupView() {
|
||||||
final LinearLayout contentPanel = (LinearLayout) mWindow.findViewById(R.id.contentPanel);
|
final ViewGroup contentPanel = (ViewGroup) mWindow.findViewById(R.id.contentPanel);
|
||||||
setupContent(contentPanel);
|
setupContent(contentPanel);
|
||||||
final boolean hasButtons = setupButtons();
|
final boolean hasButtons = setupButtons();
|
||||||
|
|
||||||
final LinearLayout topPanel = (LinearLayout) mWindow.findViewById(R.id.topPanel);
|
final ViewGroup topPanel = (ViewGroup) mWindow.findViewById(R.id.topPanel);
|
||||||
final TypedArray a = mContext.obtainStyledAttributes(
|
final TypedArray a = mContext.obtainStyledAttributes(
|
||||||
null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0);
|
null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0);
|
||||||
final boolean hasTitle = setupTitle(topPanel);
|
final boolean hasTitle = setupTitle(topPanel);
|
||||||
@@ -521,13 +522,13 @@ public class AlertController {
|
|||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupTitle(LinearLayout topPanel) {
|
private boolean setupTitle(ViewGroup topPanel) {
|
||||||
boolean hasTitle = true;
|
boolean hasTitle = true;
|
||||||
|
|
||||||
if (mCustomTitleView != null) {
|
if (mCustomTitleView != null) {
|
||||||
// Add the custom title view directly to the topPanel layout
|
// Add the custom title view directly to the topPanel layout
|
||||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
LayoutParams lp = new LayoutParams(
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
|
||||||
topPanel.addView(mCustomTitleView, 0, lp);
|
topPanel.addView(mCustomTitleView, 0, lp);
|
||||||
|
|
||||||
@@ -571,7 +572,7 @@ public class AlertController {
|
|||||||
return hasTitle;
|
return hasTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupContent(LinearLayout contentPanel) {
|
private void setupContent(ViewGroup contentPanel) {
|
||||||
mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView);
|
mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView);
|
||||||
mScrollView.setFocusable(false);
|
mScrollView.setFocusable(false);
|
||||||
|
|
||||||
@@ -588,14 +589,76 @@ public class AlertController {
|
|||||||
mScrollView.removeView(mMessageView);
|
mScrollView.removeView(mMessageView);
|
||||||
|
|
||||||
if (mListView != null) {
|
if (mListView != null) {
|
||||||
contentPanel.removeView(mWindow.findViewById(R.id.scrollView));
|
final int childIndex = mScrollView.indexOfChild(mScrollView);
|
||||||
contentPanel.addView(mListView,
|
contentPanel.removeViewAt(childIndex);
|
||||||
new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
contentPanel.addView(mListView, childIndex,
|
||||||
contentPanel.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
|
new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
||||||
} else {
|
} else {
|
||||||
contentPanel.setVisibility(View.GONE);
|
contentPanel.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up scroll indicators (if present).
|
||||||
|
final View indicatorUp = mWindow.findViewById(R.id.scrollIndicatorUp);
|
||||||
|
final View indicatorDown = mWindow.findViewById(R.id.scrollIndicatorDown);
|
||||||
|
if (indicatorUp != null || indicatorDown != null) {
|
||||||
|
if (mMessage != null) {
|
||||||
|
// We're just showing the ScrollView, set up listener.
|
||||||
|
mScrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollChange(View v, int scrollX, int scrollY,
|
||||||
|
int oldScrollX, int oldScrollY) {
|
||||||
|
manageScrollIndicators(v, indicatorUp, indicatorDown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Set up the indicators following layout.
|
||||||
|
mScrollView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
manageScrollIndicators(mScrollView, indicatorUp, indicatorDown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (mListView != null) {
|
||||||
|
// We're just showing the AbsListView, set up listener.
|
||||||
|
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||||
|
// That's cool, I guess?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScroll(AbsListView v, int firstVisibleItem,
|
||||||
|
int visibleItemCount, int totalItemCount) {
|
||||||
|
manageScrollIndicators(v, indicatorUp, indicatorDown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Set up the indicators following layout.
|
||||||
|
mListView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
manageScrollIndicators(mListView, indicatorUp, indicatorDown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// We don't have any content to scroll, remove the indicators.
|
||||||
|
if (indicatorUp != null) {
|
||||||
|
contentPanel.removeView(indicatorUp);
|
||||||
|
}
|
||||||
|
if (indicatorDown != null) {
|
||||||
|
contentPanel.removeView(indicatorDown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void manageScrollIndicators(View v, View upIndicator, View downIndicator) {
|
||||||
|
if (upIndicator != null) {
|
||||||
|
upIndicator.setVisibility(v.canScrollVertically(-1) ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
|
if (downIndicator != null) {
|
||||||
|
downIndicator.setVisibility(v.canScrollVertically(1) ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupButtons() {
|
private boolean setupButtons() {
|
||||||
|
|||||||
@@ -51,12 +51,17 @@
|
|||||||
<!-- If the client uses a customTitle, it will be added here. -->
|
<!-- If the client uses a customTitle, it will be added here. -->
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/contentPanel"
|
<FrameLayout android:id="@+id/contentPanel"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical"
|
|
||||||
android:minHeight="48dp">
|
android:minHeight="48dp">
|
||||||
|
<View android:id="@+id/scrollIndicatorUp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:background="@drawable/list_divider_material"/>
|
||||||
<ScrollView android:id="@+id/scrollView"
|
<ScrollView android:id="@+id/scrollView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -78,7 +83,13 @@
|
|||||||
android:layout_height="@dimen/alert_dialog_padding_top_material" />
|
android:layout_height="@dimen/alert_dialog_padding_top_material" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</LinearLayout>
|
<View android:id="@+id/scrollIndicatorDown"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:background="@drawable/list_divider_material"/>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<FrameLayout android:id="@+id/customPanel"
|
<FrameLayout android:id="@+id/customPanel"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -2091,7 +2091,7 @@
|
|||||||
<java-symbol type="bool" name="config_switch_phone_on_voice_reg_state_change" />
|
<java-symbol type="bool" name="config_switch_phone_on_voice_reg_state_change" />
|
||||||
<java-symbol type="string" name="whichHomeApplicationNamed" />
|
<java-symbol type="string" name="whichHomeApplicationNamed" />
|
||||||
<java-symbol type="bool" name="config_sms_force_7bit_encoding" />
|
<java-symbol type="bool" name="config_sms_force_7bit_encoding" />
|
||||||
|
|
||||||
<!-- From MSIM Account -->
|
|
||||||
<java-symbol type="layout" name="simple_account_item" />
|
<java-symbol type="layout" name="simple_account_item" />
|
||||||
|
<java-symbol type="id" name="scrollIndicatorUp" />
|
||||||
|
<java-symbol type="id" name="scrollIndicatorDown" />
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user