Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65d792e4 authored by Alan Viverette's avatar Alan Viverette Committed by Android Git Automerger
Browse files

am 10450405: Merge "Show scroll indicators in AlertDialog" into lmp-mr1-dev

* commit '10450405':
  Show scroll indicators in AlertDialog
parents 30c27afc 10450405
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -3229,6 +3229,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         */
        private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners;
        protected OnScrollChangeListener mOnScrollChangeListener;
        /**
         * Listeners for attach events.
         */
@@ -4605,6 +4607,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        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.
     *
@@ -9794,6 +9807,29 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        if (ai != null) {
            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);
    }
    /**
+74 −11
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
@@ -38,9 +37,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
@@ -449,11 +450,11 @@ public class AlertController {
    }

    private void setupView() {
        final LinearLayout contentPanel = (LinearLayout) mWindow.findViewById(R.id.contentPanel);
        final ViewGroup contentPanel = (ViewGroup) mWindow.findViewById(R.id.contentPanel);
        setupContent(contentPanel);
        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(
                null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0);
        final boolean hasTitle = setupTitle(topPanel);
@@ -521,13 +522,13 @@ public class AlertController {
        a.recycle();
    }

    private boolean setupTitle(LinearLayout topPanel) {
    private boolean setupTitle(ViewGroup topPanel) {
        boolean hasTitle = true;

        if (mCustomTitleView != null) {
            // Add the custom title view directly to the topPanel layout
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            LayoutParams lp = new LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

            topPanel.addView(mCustomTitleView, 0, lp);

@@ -571,7 +572,7 @@ public class AlertController {
        return hasTitle;
    }

    private void setupContent(LinearLayout contentPanel) {
    private void setupContent(ViewGroup contentPanel) {
        mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView);
        mScrollView.setFocusable(false);

@@ -588,14 +589,76 @@ public class AlertController {
            mScrollView.removeView(mMessageView);

            if (mListView != null) {
                contentPanel.removeView(mWindow.findViewById(R.id.scrollView));
                contentPanel.addView(mListView,
                        new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
                contentPanel.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
                final int childIndex = mScrollView.indexOfChild(mScrollView);
                contentPanel.removeViewAt(childIndex);
                contentPanel.addView(mListView, childIndex,
                        new LayoutParams(MATCH_PARENT, MATCH_PARENT));
            } else {
                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() {
+14 −3
Original line number Diff line number Diff line
@@ -51,12 +51,17 @@
        <!-- If the client uses a customTitle, it will be added here. -->
    </LinearLayout>

    <LinearLayout android:id="@+id/contentPanel"
    <FrameLayout android:id="@+id/contentPanel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        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"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
@@ -78,7 +83,13 @@
                       android:layout_height="@dimen/alert_dialog_padding_top_material" />
            </LinearLayout>
        </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"
        android:layout_width="match_parent"
+2 −2
Original line number Diff line number Diff line
@@ -2091,7 +2091,7 @@
  <java-symbol type="bool" name="config_switch_phone_on_voice_reg_state_change" />
  <java-symbol type="string" name="whichHomeApplicationNamed" />
  <java-symbol type="bool" name="config_sms_force_7bit_encoding" />

  <!-- From MSIM Account -->
  <java-symbol type="layout" name="simple_account_item" />
  <java-symbol type="id" name="scrollIndicatorUp" />
  <java-symbol type="id" name="scrollIndicatorDown" />
</resources>