Skip to content

Commit

Permalink
HALO Size (1/2)
Browse files Browse the repository at this point in the history
Change-Id: I2780dfee66b0b80b57c62b83c40609104fe3c279
  • Loading branch information
drcmda committed Jul 16, 2013
1 parent 9f7ae90 commit c3c4706
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 33 deletions.
6 changes: 6 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,12 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
*/
public static final String HALO_HIDE = "halo_hide";

/**
* HALO size fraction, default is 1.0f (normal)
* @hide
*/
public static final String HALO_SIZE = "halo_size";

/**
* HALO pause activities?, defaults to 0 (no, do not pause) on devices which isLargeRAM() == true
* otherwise it defaults to 1 (yes, do pause)
Expand Down
12 changes: 6 additions & 6 deletions packages/SystemUI/res/layout/halo_bubble.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

<ImageView
android:id="@+id/halo_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/halo_bubble_size"
android:layout_height="@dimen/halo_bubble_size"
android:src="@drawable/halo_bg"/>

<ImageView
android:id="@+id/app_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/halo_bubble_size"
android:layout_height="@dimen/halo_bubble_size"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>

<ImageView
android:id="@+id/halo_overlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/halo_bubble_size"
android:layout_height="@dimen/halo_bubble_size"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:alpha="0"/>
Expand Down
6 changes: 3 additions & 3 deletions packages/SystemUI/res/layout/halo_number.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<TextView
android:id="@+id/number"
android:animateLayoutChanges="true"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_width="@dimen/halo_number_size"
android:layout_height="@dimen/halo_number_size"
android:gravity="center"
android:background="@drawable/halo_number_shape"
android:textColor="#fff"
android:textStyle="bold"
android:textSize="14sp"/>
android:textSize="@dimen/halo_number_text_size"/>

</LinearLayout>
21 changes: 11 additions & 10 deletions packages/SystemUI/res/layout/halo_speech.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:layout_height="wrap_content">

<RelativeLayout
android:id="@+id/container"
android:layout_width="@dimen/halo_content_max_width"
android:layout_height="wrap_content">

Expand All @@ -18,33 +19,33 @@
android:id="@+id/bubble_r"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="24dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="@dimen/halo_speech_hpadding_short"
android:paddingRight="@dimen/halo_speech_hpadding_wide"
android:paddingTop="@dimen/halo_speech_vpadding_top"
android:paddingBottom="@dimen/halo_speech_vpadding_bottom"
android:background="@drawable/bubble_black_r"
android:singleLine="false"
android:maxLines = "2"
android:visibility="gone"
android:textColor="#fff"
android:textStyle="bold"
android:textSize="15sp"/>
android:textSize="@dimen/halo_speech_text_size"/>

<TextView
android:id="@+id/bubble_l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="24dp"
android:paddingRight="16dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="@dimen/halo_speech_hpadding_wide"
android:paddingRight="@dimen/halo_speech_hpadding_short"
android:paddingTop="@dimen/halo_speech_vpadding_bottom"
android:paddingBottom="@dimen/halo_speech_vpadding_bottom"
android:background="@drawable/bubble_black_l"
android:singleLine="false"
android:maxLines = "2"
android:visibility="gone"
android:textColor="#fff"
android:textStyle="bold"
android:textSize="15sp"/>
android:textSize="@dimen/halo_speech_text_size"/>

</RelativeLayout>

Expand Down
8 changes: 8 additions & 0 deletions packages/SystemUI/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@
<dimen name="pie_panel_padding">20dp</dimen>
<!-- PIE PIE PIE PIE PIE PIE PIE PIE PIE PIE PIE PIE PIE PIE -->

<dimen name="halo_bubble_size">75dp</dimen>
<dimen name="halo_number_size">24dp</dimen>
<dimen name="halo_number_text_size">14sp</dimen>
<dimen name="halo_speech_text_size">15sp</dimen>
<dimen name="halo_speech_hpadding_short">16sp</dimen>
<dimen name="halo_speech_hpadding_wide">24dp</dimen>
<dimen name="halo_speech_vpadding_top">10dp</dimen>
<dimen name="halo_speech_vpadding_bottom">10dp</dimen>
<dimen name="halo_content_max_width">250dp</dimen>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ public void onChange(boolean selfChange) {
updateHalo();
}});

mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.HALO_SIZE), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
restartHalo();
}});

updateHalo();

SettingsObserver settingsObserver = new SettingsObserver(new Handler());
Expand All @@ -547,6 +554,16 @@ protected void updateHaloButton() {
}
}

protected void restartHalo() {
if (mHalo != null) {
mHalo.cleanUp();
mWindowManager.removeView(mHalo);
mHalo = null;
}
updateNotificationIcons();
updateHalo();
}

protected void updateHalo() {
mHaloActive = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.HALO_ACTIVE, 0) == 1;
Expand Down Expand Up @@ -1429,25 +1446,29 @@ protected StatusBarNotification removeNotificationViews(IBinder key) {

private Bitmap createRoundIcon(StatusBarNotification notification) {
// Construct the round icon
BitmapDrawable bd = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.halo_bg);
int iconSize = bd.getBitmap().getWidth();
int smallIconSize = mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size);
final float haloSize = Settings.System.getFloat(mContext.getContentResolver(),
Settings.System.HALO_SIZE, 1.0f);
int iconSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
int smallIconSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
int largeIconWidth = notification.notification.largeIcon != null ? (int)(notification.notification.largeIcon.getWidth() * haloSize) : 0;
int largeIconHeight = notification.notification.largeIcon != null ? (int)(notification.notification.largeIcon.getHeight() * haloSize) : 0;
Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(roundIcon);
canvas.drawARGB(0, 0, 0, 0);

// If we have a bona fide avatar here stretching at least over half the size of our
// halo-bubble, we'll use that one and cut it round
if (notification.notification.largeIcon != null
&& notification.notification.largeIcon.getWidth() >= iconSize / 2) {
&& largeIconWidth >= iconSize / 2) {
Paint smoothingPaint = new Paint();
smoothingPaint.setAntiAlias(true);
smoothingPaint.setFilterBitmap(true);
smoothingPaint.setDither(true);
canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

Bitmap scaledBitmap = Bitmap.createScaledBitmap(notification.notification.largeIcon, iconSize, iconSize, true);
final int newWidth = iconSize;
final int newHeight = largeIconWidth / largeIconHeight * iconSize;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(notification.notification.largeIcon, newWidth, newHeight, true);
canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0,
iconSize, iconSize), smoothingPaint);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ enum Gesture {
private int oldIconIndex = -1;
private float initialX = 0;
private float initialY = 0;
private float mHaloSize = 1.0f;

// Halo dock position
SharedPreferences preferences;
Expand Down Expand Up @@ -257,10 +258,10 @@ public Halo(Context context, AttributeSet attrs, int defStyle) {
mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);

// Init variables
BitmapDrawable bd = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.halo_bg);
mIconSize = bd.getBitmap().getWidth();
mHaloSize = Settings.System.getFloat(mContext.getContentResolver(),
Settings.System.HALO_SIZE, 1.0f);
mIconSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * mHaloSize);
mIconHalfSize = mIconSize / 2;

mTriggerPos = getWMParams();

// Init colors
Expand Down Expand Up @@ -714,7 +715,7 @@ public boolean onTouchEvent(MotionEvent event) {
int items = mNotificationData.size();

// This will be the lenght we are going to use
int indexLength = (mScreenWidth - mIconSize * 2) / items;
int indexLength = ((int)(mScreenWidth * 0.9f) - mIconSize) / items;

// Calculate index
mMarkerIndex = mTickerLeft ? (items - deltaX / indexLength) - 1 : (deltaX / indexLength);
Expand Down Expand Up @@ -796,7 +797,6 @@ public boolean onTouchEvent(MotionEvent event) {
mEffect.ping(mPaintHoloBlue, 0);
} else {
setIcon(mMarkerIndex);

NotificationData.Entry entry = mNotificationData.get(mMarkerIndex);
String text = "";
if (entry.notification.notification.tickerText != null) {
Expand Down Expand Up @@ -878,6 +878,18 @@ public HaloEffect(Context context) {
mMarkerB = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.halo_marker_b);

if (mHaloSize != 1.0f) {
mBigRed = Bitmap.createScaledBitmap(mBigRed, (int)(mBigRed.getWidth() * mHaloSize),
(int)(mBigRed.getHeight() * mHaloSize), true);
mMarker = Bitmap.createScaledBitmap(mMarker, (int)(mMarker.getWidth() * mHaloSize),
(int)(mMarker.getHeight() * mHaloSize), true);
mMarkerT = Bitmap.createScaledBitmap(mMarkerT, (int)(mMarkerT.getWidth() * mHaloSize),
(int)(mMarkerT.getHeight() * mHaloSize), true);
mMarkerB = Bitmap.createScaledBitmap(mMarkerB, (int)(mMarkerB.getWidth() * mHaloSize),
(int)(mMarkerB.getHeight() * mHaloSize), true);
}


mMarkerPaint.setAntiAlias(true);
mMarkerPaint.setAlpha(0);
xPaint.setAntiAlias(true);
Expand Down Expand Up @@ -1056,7 +1068,7 @@ protected void onDraw(Canvas canvas) {
if (y > 0 && mNotificationData != null && mNotificationData.size() > 0) {
int pulseY = mHaloY + mIconHalfSize - mMarker.getHeight() / 2;
int items = mNotificationData.size();
int indexLength = (mScreenWidth - mIconSize * 2) / items;
int indexLength = ((int)(mScreenWidth * 0.9f) - mIconSize) / items;

for (int i = 0; i < items; i++) {
float pulseX = mTickerLeft ? (mIconSize * 1.15f + indexLength * i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
package com.android.systemui.statusbar.halo;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.widget.LinearLayout;
import android.animation.ObjectAnimator;
import android.view.animation.DecelerateInterpolator;
import android.util.TypedValue;
import android.provider.Settings;

import com.android.systemui.R;

Expand Down Expand Up @@ -54,14 +59,17 @@ public enum Overlay {
private Drawable mHaloCurrentOverlay;

protected View mHaloBubble;
protected ImageView mHaloIcon, mHaloOverlay;
protected ImageView mHaloBg, mHaloIcon, mHaloOverlay;

protected View mHaloContentView, mHaloTickerContent;
protected TextView mHaloTextViewR, mHaloTextViewL;
protected RelativeLayout mHaloTickerContainer;

protected View mHaloNumberView;
protected TextView mHaloNumber;

private float mFraction = 1.0f;

CustomObjectAnimator mHaloOverlayAnimator;

public HaloProperties(Context context) {
Expand All @@ -77,10 +85,12 @@ public HaloProperties(Context context) {
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

mHaloBubble = mInflater.inflate(R.layout.halo_bubble, null);
mHaloBg = (ImageView) mHaloBubble.findViewById(R.id.halo_bg);
mHaloIcon = (ImageView) mHaloBubble.findViewById(R.id.app_icon);
mHaloOverlay = (ImageView) mHaloBubble.findViewById(R.id.halo_overlay);

mHaloContentView = mInflater.inflate(R.layout.halo_speech, null);
mHaloTickerContainer = (RelativeLayout)mHaloContentView.findViewById(R.id.container);
mHaloTickerContent = mHaloContentView.findViewById(R.id.ticker);
mHaloTextViewR = (TextView) mHaloTickerContent.findViewById(R.id.bubble_r);
mHaloTextViewL = (TextView) mHaloTickerContent.findViewById(R.id.bubble_l);
Expand All @@ -91,8 +101,33 @@ public HaloProperties(Context context) {
mHaloNumber = (TextView) mHaloNumberView.findViewById(R.id.number);
mHaloNumber.setAlpha(0f);

mFraction = Settings.System.getFloat(mContext.getContentResolver(),
Settings.System.HALO_SIZE, 1.0f);
setHaloSize(mFraction);

mHaloOverlayAnimator = new CustomObjectAnimator(this);
}
}

public void setHaloSize(float fraction) {

final int newBubbleSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * fraction);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(newBubbleSize, newBubbleSize);
mHaloBg.setLayoutParams(layoutParams);
mHaloIcon.setLayoutParams(layoutParams);
mHaloOverlay.setLayoutParams(layoutParams);

final int newNumberSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.halo_number_size) * fraction);
final int newNumberTextSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.halo_number_text_size) * fraction);
LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(newNumberSize, newNumberSize);
mHaloNumber.setLayoutParams(layoutParams2);
mHaloNumber.setTextSize(TypedValue.COMPLEX_UNIT_PX, newNumberTextSize);

final int newSpeechTextSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.halo_speech_text_size) * fraction);
mHaloTextViewR.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSpeechTextSize);
mHaloTextViewL.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSpeechTextSize);

updateResources();
}

public void setHaloX(int value) {
mHaloX = value;
Expand Down Expand Up @@ -159,6 +194,12 @@ public void setHaloOverlay(Overlay overlay, float overlayAlpha) {
}

public void updateResources() {

final int iconSize = (int)(mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * mFraction);
final int newSize = (int)(getWidth() * 0.9f) - iconSize;
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(newSize, LinearLayout.LayoutParams.WRAP_CONTENT);
mHaloTickerContainer.setLayoutParams(layoutParams);

mHaloContentView.measure(MeasureSpec.getSize(mHaloContentView.getMeasuredWidth()),
MeasureSpec.getSize(mHaloContentView.getMeasuredHeight()));
mHaloContentView.layout(0, 0, 0, 0);
Expand Down

0 comments on commit c3c4706

Please sign in to comment.