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

Commit 5bf069a0 authored by Selim Cinek's avatar Selim Cinek
Browse files

Updated the media notification template

The media notification now lives in the new world
with the appropriate notification header.

Change-Id: Ifed0f12e4925e27a303f6f01faa2e9c17262d486
parent 65b2e7c6
Loading
Loading
Loading
Loading
+18 −44
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import android.os.Parcelable;
import android.os.SystemClock;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.LayoutDirection;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
@@ -3381,7 +3380,7 @@ public class Notification implements Parcelable
            }
        }

        private int resolveColor() {
        int resolveColor() {
            if (mN.color == COLOR_DEFAULT) {
                return mContext.getColor(R.color.notification_icon_default_color);
            }
@@ -4224,14 +4223,13 @@ public class Notification implements Parcelable
            }
        }

        private RemoteViews generateMediaActionButton(Action action) {
        private RemoteViews generateMediaActionButton(Action action, int color) {
            final boolean tombstone = (action.actionIntent == null);
            RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(),
                    R.layout.notification_material_media_action);
            button.setImageViewIcon(R.id.action0, action.getIcon());
            button.setDrawableParameters(R.id.action0, false, -1,
                    0xFFFFFFFF,
                    PorterDuff.Mode.SRC_ATOP, -1);
            button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP,
                    -1);
            if (!tombstone) {
                button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
            }
@@ -4257,64 +4255,40 @@ public class Notification implements Parcelable
                    }

                    final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]);
                    final RemoteViews button = generateMediaActionButton(action);
                    final RemoteViews button = generateMediaActionButton(action,
                            mBuilder.resolveColor());
                    view.addView(com.android.internal.R.id.media_actions, button);
                }
            }
            styleText(view);
            hideRightIcon(view);
            handleImage(view  /* addPaddingToMainColumn */);
            return view;
        }

        private RemoteViews makeMediaBigContentView() {
            final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS);
            RemoteViews big = mBuilder.applyStandardTemplate(getBigLayoutResource(actionCount),
                    false /* hasProgress */);
            RemoteViews big = mBuilder.applyStandardTemplate(
                    R.layout.notification_template_material_big_media,
                    false);

            if (actionCount > 0) {
                big.removeAllViews(com.android.internal.R.id.media_actions);
                for (int i = 0; i < actionCount; i++) {
                    final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i));
                    final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i),
                            mBuilder.resolveColor());
                    big.addView(com.android.internal.R.id.media_actions, button);
                }
            }
            styleText(big);
            hideRightIcon(big);
            handleImage(big);
            big.setViewVisibility(android.R.id.progress, View.GONE);
            return big;
        }

        private int getBigLayoutResource(int actionCount) {
            if (actionCount <= 3) {
                return R.layout.notification_template_material_big_media_narrow;
            } else {
                return R.layout.notification_template_material_big_media;
            }
        }

        private void hideRightIcon(RemoteViews contentView) {
            contentView.setViewVisibility(R.id.right_icon, View.GONE);
        }

        /**
         * Applies the special text colors for media notifications to all text views.
         */
        private void styleText(RemoteViews contentView) {
            int primaryColor = mBuilder.mContext.getColor(
                    R.color.notification_media_primary_color);
            int secondaryColor = mBuilder.mContext.getColor(
                    R.color.notification_media_secondary_color);
            contentView.setTextColor(R.id.title, primaryColor);
            if (mBuilder.showsTimeOrChronometer()) {
                if (mBuilder.getAllExtras().getBoolean(EXTRA_SHOW_CHRONOMETER)) {
                    contentView.setTextColor(R.id.chronometer, secondaryColor);
                } else {
                    contentView.setTextColor(R.id.time, secondaryColor);
                }
        private void handleImage(RemoteViews contentView) {
            if (mBuilder.mN.mLargeIcon != null) {
                contentView.setViewLayoutMarginEnd(R.id.line1, 0);
                contentView.setViewLayoutMarginEnd(R.id.line2, 0);
                contentView.setViewLayoutMarginEnd(R.id.line3, 0);
            }
            contentView.setTextColor(R.id.text2, secondaryColor);
            contentView.setTextColor(R.id.text, secondaryColor);
            contentView.setTextColor(R.id.info, secondaryColor);
        }

        /**
+6 −4
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@
    style="@android:style/Widget.Material.Button.Borderless.Small"
    android:id="@+id/action0"
    android:layout_width="48dp"
    android:layout_height="match_parent"
    android:layout_marginLeft="2dp"
    android:layout_marginRight="2dp"
    android:layout_weight="1"
    android:layout_height="48dp"
    android:paddingBottom="8dp"
    android:paddingTop="8dp"
    android:paddingStart="8dp"
    android:paddingEnd="8dp"
    android:layout_marginEnd="2dp"
    android:gravity="center"
    android:background="@drawable/notification_material_media_action_background"
    />
+25 −16
Original line number Diff line number Diff line
@@ -15,45 +15,54 @@
  ~ limitations under the License
  -->

<!-- Layout for the expanded media notification -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="128dp"
    android:background="#00000000"
    android:tag="bigMedia"
    android:tag="bigMediaNarrow"
    >
    <include layout="@layout/notification_template_header" />
    <include layout="@layout/notification_template_header"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:layout_marginEnd="106dp"/>
    <LinearLayout
        android:id="@+id/notification_main_column"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/notification_content_margin_start"
        android:layout_marginTop="@dimen/notification_content_margin_top"
        android:layout_marginEnd="@dimen/notification_content_margin_end"
        android:minHeight="@dimen/notification_large_icon_height"
        android:layout_marginStart="@dimen/notification_content_margin_start"
        android:layout_marginEnd="24dp"
        android:layout_toStartOf="@id/right_icon"
        android:minHeight="54dp"
        android:orientation="vertical"
        >
        <include layout="@layout/notification_template_part_line1" />
        <include layout="@layout/notification_template_part_line2" />
        <include layout="@layout/notification_template_part_line3" />
    </LinearLayout>
    <include layout="@layout/notification_template_right_icon" />
    <LinearLayout
        android:id="@+id/media_actions"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:layout_alignParentStart="true"
        android:paddingStart="8dp"
        android:paddingBottom="8dp"
        android:orientation="horizontal"
        android:layoutDirection="ltr"
        >
        <!-- media buttons will be added here -->
    </LinearLayout>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_above="@id/media_actions"
        android:id="@+id/action_divider"
        android:background="@drawable/notification_template_divider_media" />

    <ImageView android:id="@+id/right_icon"
        android:layout_width="96dp"
        android:layout_height="96dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="16dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:scaleType="centerCrop"
        />
</RelativeLayout>
+0 −64
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2014 The Android Open Source 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
  -->

<!-- Layout to be used with only max 3 actions. It has a much larger picture at the left side-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="128dp"
    android:background="#00000000"
    android:tag="bigMediaNarrow"
    >
    <include layout="@layout/notification_template_header" />
    <LinearLayout
        android:id="@+id/notification_main_column"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/notification_content_margin_start"
        android:layout_marginTop="@dimen/notification_content_margin_top"
        android:layout_marginEnd="@dimen/notification_content_margin_end"
        android:minHeight="@dimen/notification_large_icon_height"
        android:orientation="vertical"
        >
        <include layout="@layout/notification_template_part_line1" />
        <include layout="@layout/notification_template_part_line2" />
        <include layout="@layout/notification_template_part_line3" />
    </LinearLayout>
    <include layout="@layout/notification_template_right_icon"
        android:layout_toEndOf="@id/icon"
        android:layout_marginStart="12dp"/>
    <LinearLayout
        android:id="@+id/media_actions"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_toEndOf="@id/right_icon"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:orientation="horizontal"
        android:layoutDirection="ltr"
        >
        <!-- media buttons will be added here -->
    </LinearLayout>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_toEndOf="@id/icon"
        android:layout_above="@id/media_actions"
        android:id="@+id/action_divider"
        android:background="@drawable/notification_template_divider_media" />
</RelativeLayout>
+11 −6
Original line number Diff line number Diff line
@@ -22,16 +22,19 @@
    android:layout_height="wrap_content"
    android:tag="media"
    >
    <include layout="@layout/notification_template_header" />
    <include layout="@layout/notification_template_header"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:layout_marginEnd="106dp"/>
    <LinearLayout
        android:id="@+id/notification_main_column"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:layout_height="54dp"
        android:background="#00000000"
        android:orientation="horizontal"
        android:layout_marginStart="@dimen/notification_content_margin_start"
        android:layout_marginTop="@dimen/notification_content_margin_top"
        android:layout_marginEnd="@dimen/notification_content_margin_end"
        android:layout_marginEnd="72dp"
        android:tag="media"
        >
        <LinearLayout
@@ -39,7 +42,7 @@
            android:layout_height="wrap_content"
            android:layout_gravity="fill_vertical"
            android:layout_weight="1"
            android:minHeight="@dimen/notification_large_icon_height"
            android:minHeight="54dp"
            android:orientation="vertical"
            >
            <include layout="@layout/notification_template_part_line1"/>
@@ -50,12 +53,14 @@
            android:id="@+id/media_actions"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical|end"
            android:layout_marginEnd="-8dp"
            android:layout_gravity="bottom|end"
            android:layout_marginStart="10dp"
            android:layout_marginBottom="8dp"
            android:layoutDirection="ltr"
            android:orientation="horizontal"
            >
            <!-- media buttons will be added here -->
        </LinearLayout>
    </LinearLayout>
    <include layout="@layout/notification_template_right_icon" />
</FrameLayout>
Loading