Skip to content

Commit

Permalink
add Pie StatusPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
Squadzone committed Mar 8, 2013
1 parent 72a22d3 commit e9616ed
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 52 deletions.
35 changes: 35 additions & 0 deletions packages/SystemUI/res/layout/pie_expanded_panel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- Copyright (C) 2013 ParanoidAndroid Project
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.
-->

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
android:id="@+id/content_frame"
android:background="#AA000000"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">

<ScrollView
android:id="@+id/content_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:fadingEdge="none"
android:overScrollMode="ifContentScrolls"/>

</LinearLayout>
1 change: 1 addition & 0 deletions packages/SystemUI/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@
<dimen name="pie_touch_offset">15dp</dimen>
<dimen name="pie_tab_title_height">24dp</dimen>
<dimen name="pie_item_size">40dp</dimen>
<dimen name="pie_panel_padding">20dp</dimen>
</resources>

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public boolean dispatchTouchEvent(MotionEvent event) {
* otherwise we get into a loop
*/
if (!mEventsControlledByDispatcher) {
handled = mDispatcher.handleTouchEvent(event);
//handled = mDispatcher.handleTouchEvent(event);
}

if (DBG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ public void setNotifNew(boolean notifnew) {
}
}

public void resetStatus(int numb) {
public void hidePanels(boolean wth) {
if (mPie != null) {
mPie.resetStatus(-1);
mPie.hidePanels(wth);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ public NotificationData setNotifications(NotificationData list) {
return list;
}

public void resetStatus(int numb) {
public void hidePanels(boolean wth) {
if (mPieControl != null) {
mPieControl.resetStatus(-1);
mPieControl.hidePanels(wth);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,38 @@

package com.android.systemui.statusbar;

import android.animationing.ValueAnimator;
import android.animationing.ValueAnimator.AnimatorUpdateListener;
import android.database.ContentObserver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.Handler;
import android.provider.Settings;
import android.view.animation.DecelerateInterpolator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.View.OnTouchListener;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.widget.ScrollView;

import com.android.systemui.R;
import com.android.systemui.statusbar.quicksettings.QuickSettingsContainerView;

public class PieStatusPanel {

Expand All @@ -28,13 +56,69 @@ public class PieStatusPanel {

private Context mContext;
private PieControlPanel mPanel;
private ScrollView mScrollView;
private View mContentFrame;
private QuickSettingsContainerView mQS;
private LinearLayout mNotificationPanel;
private ViewGroup[] mPanelParents = new ViewGroup[2];

private int mCurrentViewState = -1;
private int mFlipViewState = -1;

public PieStatusPanel(Context context, PieControlPanel panel) {
mContext = context;
mPanel = panel;

if (Settings.System.getInt(context.getContentResolver(), Settings.System.EXPANDED_VIEW_WIDGET, 5) == 5) {
mNotificationPanel = mPanel.getBar().getNotificationLinearLayout();
mNotificationPanel.setTag(NOTIFICATIONS_PANEL);
mQS = mPanel.getBar().getQuickSettingsPanel();
mQS.setTag(QUICK_SETTINGS_PANEL);

mPanelParents[NOTIFICATIONS_PANEL] = (ViewGroup) mNotificationPanel.getParent();
mPanelParents[QUICK_SETTINGS_PANEL] = (ViewGroup) mQS.getParent();

mContentFrame = (View) mPanel.getBar().mContainer.findViewById(R.id.content_frame);
mScrollView = (ScrollView) mPanel.getBar().mContainer.findViewById(R.id.content_scroll);
mScrollView.setOnTouchListener(new ViewOnTouchListener());
mContentFrame.setOnTouchListener(new ViewOnTouchListener());
} else {
mNotificationPanel = null;
mQS = null;
}
mPanel.getBar().mContainer.setVisibility(View.GONE);
}

class ViewOnTouchListener implements OnTouchListener {
final int SCROLLING_DISTANCE_TRIGGER = 100;
float scrollX;
float scrollY;
boolean hasScrolled;

@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
scrollX = event.getX();
scrollY = event.getY();
hasScrolled = false;
break;
case MotionEvent.ACTION_MOVE:
float distanceY = Math.abs(event.getY() - scrollY);
float distanceX = Math.abs(event.getX() - scrollX);
if(distanceY > SCROLLING_DISTANCE_TRIGGER ||
distanceX > SCROLLING_DISTANCE_TRIGGER) {
hasScrolled = true;
}
break;
case MotionEvent.ACTION_UP:
if(!hasScrolled) {
hidePanels(true);
}
break;
}
return false;
}
}

public int getFlipViewState() {
Expand All @@ -54,25 +138,100 @@ public void setCurrentViewState(int state) {
}

public void hidePanels(boolean reset) {
if (mCurrentViewState == NOTIFICATIONS_PANEL) {
if (mNotificationPanel != null) hidePanel(mNotificationPanel);
} else if (mCurrentViewState == QUICK_SETTINGS_PANEL) {
if (mQS != null) hidePanel(mQS);
}
if (reset) mCurrentViewState = -1;
}

public void swapPanels() {
hidePanels(false);
if (mCurrentViewState == NOTIFICATIONS_PANEL) {
mCurrentViewState = QUICK_SETTINGS_PANEL;
mPanel.getBar().toggleNotif();
if (mQS != null) showPanel(mQS);
} else if (mCurrentViewState == QUICK_SETTINGS_PANEL) {
mCurrentViewState = NOTIFICATIONS_PANEL;
mPanel.getBar().togglePower();
if (mNotificationPanel != null) showPanel(mNotificationPanel);
}
}

private ViewGroup getPanelParent(View panel) {
if (((Integer)panel.getTag()).intValue() == NOTIFICATIONS_PANEL) {
return mPanelParents[NOTIFICATIONS_PANEL];
} else {
return mPanelParents[QUICK_SETTINGS_PANEL];
}
}

public void showTilesPanel() {
mPanel.getBar().animateExpand();
mPanel.getBar().toggleNotif();
if (mQS != null) showPanel(mQS);
}

public void showNotificationsPanel() {
mPanel.getBar().IntroducerView();
if (mNotificationPanel != null) showPanel(mNotificationPanel);
}

public void hideTilesPanel() {
if (mQS != null) hidePanel(mQS);
}

public void hideNotificationsPanel() {
if (mNotificationPanel != null) hidePanel(mNotificationPanel);
}

private void showPanel(View panel) {
mContentFrame.setBackgroundColor(0);
ValueAnimator alphAnimation = ValueAnimator.ofInt(0, 1);
alphAnimation.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mScrollView.setX(-(int)((1-animation.getAnimatedFraction()) * mPanel.getWidth() * 1.5));
mContentFrame.setBackgroundColor((int)(animation.getAnimatedFraction() * 0xEE) << 24);
mPanel.invalidate();
}
});
alphAnimation.setDuration(600);
alphAnimation.setInterpolator(new DecelerateInterpolator());
alphAnimation.start();

ViewGroup parent = getPanelParent(panel);
parent.removeAllViews();
mScrollView.removeAllViews();
mScrollView.addView(panel);
updateContainer(true);
}

private void hidePanel(View panel) {
ViewGroup parent = getPanelParent(panel);
mScrollView.removeAllViews();
parent.removeAllViews();
parent.addView(panel, panel.getLayoutParams());
updateContainer(false);
}

private void updateContainer(boolean visible) {
mPanel.getBar().mContainer.setVisibility(visible ? View.VISIBLE : View.GONE);
updatePanelConfiguration();
}

public void updatePanelConfiguration() {
if ((mQS == null) || (mNotificationPanel == null)) return;
int padding = mContext.getResources().getDimensionPixelSize(R.dimen.pie_panel_padding);
mScrollView.setPadding(padding,0,padding,0);
}

public static WindowManager.LayoutParams getFlipPanelLayoutParams() {
return new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
0
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
}
}
Loading

0 comments on commit e9616ed

Please sign in to comment.