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

Commit 31995438 authored by Keyan Mobli's avatar Keyan Mobli
Browse files

Add Now Playing to the Lockscreen

Change-Id: Iea60dc013f2051cda85c3f76931cd18a8ce23afe
parent 49c07727
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -253,5 +253,18 @@
            android:background="@color/transparent"
            android:visibility="gone"
            />
        <TextView
            android:id="@+id/musicNowPlaying"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:lines="1"
            android:scrollHorizontally="true"
            android:ellipsize="marquee"
            android:paddingTop="10dip"
            android:gravity="bottom"
            android:layout_alignWithParentIfMissing="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            />
    </RelativeLayout>
</android.gesture.GestureOverlayView>
+17 −8
Original line number Diff line number Diff line
@@ -167,8 +167,7 @@
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="15dip"
        android:padding="10px"
        android:layout_marginBottom="6dip"
        android:background="@color/transparent"
        android:visibility="gone"
        />
@@ -179,8 +178,7 @@
        android:src="@drawable/ic_media_pause"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="15dip"
        android:padding="10px"
        android:layout_marginBottom="6dip"
        android:background="@color/transparent"
        android:visibility="gone"
        />
@@ -190,9 +188,8 @@
        android:layout_height="wrap_content"
        android:src="@drawable/ic_media_previous"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="15dip"
        android:layout_marginBottom="6dip"
        android:layout_marginRight="20dip"
        android:padding="10px"
        android:layout_toLeftOf="@+id/musicControlPause"
        android:background="@color/transparent"
        android:visibility="gone"
@@ -203,13 +200,25 @@
        android:layout_height="wrap_content"
        android:src="@drawable/ic_media_next"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="15dip"
        android:layout_marginBottom="6dip"
        android:layout_marginLeft="20dip"
        android:padding="10px"
        android:layout_toRightOf="@+id/musicControlPause"
        android:background="@color/transparent"
        android:visibility="gone"
        />
    <TextView
        android:id="@+id/musicNowPlaying"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:lines="1"
        android:scrollHorizontally="true"
        android:ellipsize="marquee"
        android:paddingTop="40dip"
        android:gravity="bottom"
        android:layout_alignWithParentIfMissing="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        />

    </RelativeLayout>

+4 −0
Original line number Diff line number Diff line
@@ -344,4 +344,8 @@ public class AccountUnlockScreen extends RelativeLayout implements KeyguardScree
    public void onTimeChanged() {

    }

    public void onMusicChanged() {

    }
}
+17 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public class KeyguardUpdateMonitor {
    private static final int MSG_SIM_STATE_CHANGE = 304;
    private static final int MSG_RINGER_MODE_CHANGED = 305;
    private static final int MSG_PHONE_STATE_CHANGED = 306;
    private static final int MSG_MUSIC_SONG_CHANGE = 307;


    /**
@@ -163,6 +164,9 @@ public class KeyguardUpdateMonitor {
                    case MSG_PHONE_STATE_CHANGED:
                        handlePhoneStateChanged((String)msg.obj);
                        break;
                    case MSG_MUSIC_SONG_CHANGE:
                        handleSongUpdate();
                        break;
                }
            }
        };
@@ -218,6 +222,7 @@ public class KeyguardUpdateMonitor {
        filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
        filter.addAction(SPN_STRINGS_UPDATED_ACTION);
        filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
        filter.addAction("internal.policy.impl.updateSongStatus");
        context.registerReceiver(new BroadcastReceiver() {

            public void onReceive(Context context, Intent intent) {
@@ -251,6 +256,8 @@ public class KeyguardUpdateMonitor {
                } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
                    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                    mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state));
                } else if ("internal.policy.impl.updateSongStatus".equals(action)){
                    mHandler.sendMessage(mHandler.obtainMessage(MSG_MUSIC_SONG_CHANGE));
                }
            }
        }, filter);
@@ -328,6 +335,15 @@ public class KeyguardUpdateMonitor {
        }
    }

    /**
     * Handle {@link #MSG_MUSIC_SONG_CHANGED}
     */
    private void handleSongUpdate() {
        for (int i = 0; i< mInfoCallbacks.size(); i++) {
            mInfoCallbacks.get(i).onMusicChanged();
        }
    }

    /**
     * @param status One of the statuses of {@link android.os.BatteryManager}
     * @return Whether the status maps to a status for being plugged in.
@@ -405,6 +421,7 @@ public class KeyguardUpdateMonitor {
    interface InfoCallback {
        void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel);
        void onTimeChanged();
        void onMusicChanged();

        /**
         * @param plmn The operator name of the registered network.  May be null if it shouldn't
+31 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManagerImpl;
import android.view.WindowManagerPolicy;
import android.widget.TextView;


/**
@@ -245,6 +246,10 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
     */
    private boolean mWaitingUntilKeyguardVisible = false;

    private static String mArtist = null;
    private static String mTrack = null;
    private static Boolean mPlaying = null;

    public KeyguardViewMediator(Context context, PhoneWindowManager callback,
            LocalPowerManager powerManager) {
        mContext = context;
@@ -269,6 +274,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
        context.registerReceiver(mBroadCastReceiver, filter);
        mAlarmManager = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);

        mCallback = callback;

        mUpdateMonitor = new KeyguardUpdateMonitor(context);
@@ -286,6 +292,12 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
        mUserPresentIntent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

        final ContentResolver cr = mContext.getContentResolver();

        IntentFilter iF = new IntentFilter();
        iF.addAction("com.android.music.metachanged");
        iF.addAction("com.android.music.playstatechanged");
        mContext.registerReceiver(mMusicReceiver, iF);

        mShowLockIcon = (Settings.System.getInt(cr, "show_status_bar_lock", 0) == 1);
    }

@@ -1161,6 +1173,25 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
            mKeyguardViewManager.onScreenTurnedOn();
        }
    }
    private BroadcastReceiver mMusicReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            mArtist = intent.getStringExtra("artist");
            mTrack = intent.getStringExtra("track");
            mPlaying = intent.getBooleanExtra("playing", false);
            intent = new Intent("internal.policy.impl.updateSongStatus");
            context.sendBroadcast(intent);
        }
    };
    public static String NowPlaying() {
        if (mArtist != null && mPlaying) {
            return (mArtist + " - " + mTrack);
        } else {
            return "";
        }
    }
}

Loading