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

Commit 6ec9ea72 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: add circle page indicator for qs tiles



Change-Id: Ie6811657d3888e260b757a44f7535e6b6caec644
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 601bd9b4
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 Jake Wharton
     Copyright (C) 2011 Patrik Åkerfeldt

     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.
-->

<resources>
    <attr name="centered" format="boolean" />
    <attr name="selectedColor" format="color" />
    <attr name="strokeWidth" format="dimension" />
    <attr name="unselectedColor" format="color" />

    <declare-styleable name="CirclePageIndicator">
        <!-- Whether or not the indicators should be centered. -->
        <attr name="centered" />
        <!-- Color of the filled circle that represents the current page. -->
        <attr name="indicatorFillColor" format="color" />
        <!-- Color of the filled circles that represents pages. -->
        <attr name="pageColor" format="color" />
        <!-- Orientation of the indicator. -->
        <attr name="android:orientation"/>
        <!-- Radius of the circles. This is also the spacing between circles. -->
        <attr name="radius" format="dimension" />
        <!-- Whether or not the selected indicator snaps to the circles. -->
        <attr name="snap" format="boolean" />
        <!-- Color of the open circles. -->
        <attr name="strokeColor" format="color" />
        <!-- Width of the stroke used to draw the circles. -->
        <attr name="strokeWidth" />
        <!-- View background -->
        <attr name="android:background"/>
    </declare-styleable>
</resources>
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 Jake Wharton

     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.
-->

<resources>
    <bool name="default_circle_indicator_centered">true</bool>
    <color name="default_circle_indicator_fill_color">#ffFFFFFF</color>
    <color name="default_circle_indicator_page_color">#ffcccccc</color>
    <integer name="default_circle_indicator_orientation">0</integer>
    <dimen name="default_circle_indicator_radius">3dp</dimen>
    <bool name="default_circle_indicator_snap">false</bool>
    <color name="default_circle_indicator_stroke_color">#ffcccccc</color>
    <dimen name="default_circle_indicator_stroke_width">0dp</dimen>
</resources>
+27 −20
Original line number Diff line number Diff line
@@ -18,21 +18,17 @@ package com.android.systemui.qs;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.DragEvent;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,7 +36,6 @@ import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.R;
import com.android.systemui.qs.tiles.EditTile;
@@ -50,7 +45,7 @@ import com.android.systemui.settings.ToggleSlider;
import com.android.systemui.statusbar.phone.QSTileHost;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.tuner.QsTuner;
import cyanogenmod.providers.CMSettings;
import com.viewpagerindicator.CirclePageIndicator;

import java.util.ArrayList;
import java.util.Arrays;
@@ -70,6 +65,7 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
    protected QSViewPager mViewPager;
    protected PagerAdapter mPagerAdapter;
    QSPanelTopView mQsPanelTop;
    CirclePageIndicator mPageIndicator;

    private DragTileRecord mDraggingRecord;
    private boolean mEditing;
@@ -120,8 +116,10 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
                });
        mViewPager = new QSViewPager(getContext());

        mPageIndicator = new CirclePageIndicator(getContext());
        addView(mDetail);
        addView(mViewPager);
        addView(mPageIndicator);
        addView(mFooter.getView());

        mClipper = new QSDetailClipper(mDetail);
@@ -178,7 +176,11 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
                return view == object;
            }
        };
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setCurrentItem(0);

        mPageIndicator.setViewPager(mViewPager);
        mPageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset,
                                       int positionOffsetPixels) {
@@ -210,8 +212,6 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On

            }
        });
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setCurrentItem(0);

        setClipChildren(false);
        updateResources();
@@ -470,14 +470,13 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        final int width = MeasureSpec.getSize(widthMeasureSpec);

        mQsPanelTop.measure(exactly(width), MeasureSpec.UNSPECIFIED);

        final int brightnessHeight = mQsPanelTop.getMeasuredHeight();

        mFooter.getView().measure(exactly(width), MeasureSpec.UNSPECIFIED);

        mViewPager.measure(exactly(width), MeasureSpec.UNSPECIFIED);
        mPageIndicator.measure(exactly(width), MeasureSpec.UNSPECIFIED);
        mFooter.getView().measure(exactly(width), MeasureSpec.UNSPECIFIED);

        int h = brightnessHeight + mViewPager.getMeasuredHeight();
        int h = mQsPanelTop.getMeasuredHeight()
                + mViewPager.getMeasuredHeight()
                + mPageIndicator.getMeasuredHeight();
        if (mFooter.hasFooter()) {
            h += mFooter.getView().getMeasuredHeight();
        }
@@ -507,12 +506,20 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        if (DEBUG_DRAG) Log.d(TAG, "onLayout()");
        final int w = getWidth();

        mQsPanelTop.layout(0, t, mQsPanelTop.getMeasuredWidth(),
                t + mQsPanelTop.getMeasuredHeight());
        int top = 0;
        mQsPanelTop.layout(0, top, w, top + mQsPanelTop.getMeasuredHeight());
        top += mQsPanelTop.getMeasuredHeight();

        mViewPager.layout(0, top, w, top + mViewPager.getMeasuredHeight());
        top += mViewPager.getMeasuredHeight();

        // layout page indicator below view pager
        mPageIndicator.layout(0, top, w, top + mPageIndicator.getMeasuredHeight());

        // detail takes up whole height
        final int dh = Math.max(mDetail.getMeasuredHeight(), mViewPager.getMeasuredHeight());
        mViewPager.layout(0, t + mQsPanelTop.getMeasuredHeight(), w, t + dh);
        mDetail.layout(0, t, mDetail.getMeasuredWidth(), t + dh);
        mDetail.layout(0, 0, mDetail.getMeasuredWidth(), getMeasuredHeight());

        if (mFooter.hasFooter()) {
            View footer = mFooter.getView();
            footer.layout(0, getMeasuredHeight() - footer.getMeasuredHeight(),
+505 −0

File added.

Preview size limit exceeded, changes collapsed.

+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 Patrik Akerfeldt
 * Copyright (C) 2011 Jake Wharton
 *
 * 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.viewpagerindicator;

import android.support.v4.view.ViewPager;

/**
 * A PageIndicator is responsible to show an visual indicator on the total views
 * number and the current visible view.
 */
public interface PageIndicator extends ViewPager.OnPageChangeListener {
    /**
     * Bind the indicator to a ViewPager.
     *
     * @param view
     */
    void setViewPager(ViewPager view);

    /**
     * Bind the indicator to a ViewPager.
     *
     * @param view
     * @param initialPosition
     */
    void setViewPager(ViewPager view, int initialPosition);

    /**
     * <p>Set the current page of both the ViewPager and indicator.</p>
     *
     * <p>This <strong>must</strong> be used if you need to set the page before
     * the views are drawn on screen (e.g., default start page).</p>
     *
     * @param item
     */
    void setCurrentItem(int item);

    /**
     * Set a page change listener which will receive forwarded events.
     *
     * @param listener
     */
    void setOnPageChangeListener(ViewPager.OnPageChangeListener listener);

    /**
     * Notify the indicator that the fragment list has changed.
     */
    void notifyDataSetChanged();
}