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

Commit ae5a9d4a authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Fix 5044158: Initial pass: add music transport controls to LockScreen"

parents 6903a7de 6b05d580
Loading
Loading
Loading
Loading
+18 −12
Original line number Original line Diff line number Diff line
@@ -891,18 +891,6 @@ public class LockPatternUtils {
        button.setText(textId);
        button.setText(textId);
    }
    }


    /**
     * Sets the visibility of emergency call prompt based on emergency capable
     * @param emergencyText the emergency call text to be updated
     */
    public void updateEmergencyCallText(TextView emergencyText) {
        if (isEmergencyCallCapable()) {
            emergencyText.setVisibility(View.VISIBLE);
        } else {
            emergencyText.setVisibility(View.GONE);
        }
    }

    /**
    /**
     * Resumes a call in progress. Typically launched from the EmergencyCall button
     * Resumes a call in progress. Typically launched from the EmergencyCall button
     * on various lockscreens.
     * on various lockscreens.
@@ -920,4 +908,22 @@ public class LockPatternUtils {
        }
        }
        return false;
        return false;
    }
    }

    /**
     * Performs concentenation of PLMN/SPN
     * @param plmn
     * @param spn
     * @return
     */
    public static CharSequence getCarrierString(CharSequence plmn, CharSequence spn) {
        if (plmn != null && spn == null) {
            return plmn;
        } else if (plmn != null && spn != null) {
            return plmn + "|" + spn;
        } else if (plmn == null && spn != null) {
            return spn;
        } else {
            return "";
        }
    }
}
}
+36 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2011 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.
 */

package com.android.internal.widget;

import android.view.View;

/**
 * An interface used by LockScreenWidgets to send messages to lock screen.
 */
public interface LockScreenWidgetCallback {
    // Sends a message to lock screen requesting the given view be shown.  May be ignored, depending
    // on lock screen state. View must be the top-level lock screen widget or it will be ignored.
    public void requestShow(View self);

    // Sends a message to lock screen requesting the view to be hidden.
    public void requestHide(View self);

    // Sends a message to lock screen that user has interacted with widget. This should be used
    // exclusively in response to user activity, i.e. user hits a button in the view.
    public void userActivity(View self);

}
+23 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2011 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.
 */

package com.android.internal.widget;

public interface LockScreenWidgetInterface {

    public void setCallback(LockScreenWidgetCallback callback);

}
+103 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2011 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.
 */

package com.android.internal.widget;

import com.android.internal.R;

import android.content.Context;
import android.media.AudioManager;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

/**
 * A special widget for displaying audio playback ("transport controls") in LockScreen.
 *
 */
public class TransportControlView extends LinearLayout implements LockScreenWidgetInterface,
        OnClickListener {
    private static final String TAG = "TransportControlView";
    static final int sViewIds[] = { R.id.control_prev, R.id.control_pauseplay, R.id.control_next };
    protected static final int AUDIO_FOCUS_CHANGED = 100;
    private LockScreenWidgetCallback mCallback;

    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what){
            case AUDIO_FOCUS_CHANGED:
                handleAudioFocusChange(msg.arg1);
            }
        }
    };

    AudioManager.OnAudioFocusChangeListener mAudioFocusChangeListener =
        new AudioManager.OnAudioFocusChangeListener() {
            public void onAudioFocusChange(final int focusChange) {
                mHandler.obtainMessage(AUDIO_FOCUS_CHANGED, focusChange, 0).sendToTarget();
            }
        };

    public TransportControlView(Context context) {
        this(context, null);
    }

    public TransportControlView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    protected void handleAudioFocusChange(int focusChange) {
        // TODO
    }

    public void setCallback(LockScreenWidgetCallback callback) {
        mCallback = callback;
    }

    @Override
    public void onFinishInflate() {
        for (int i = 0; i < sViewIds.length; i++) {
            View view = findViewById(sViewIds[i]);
            if (view != null) {
                view.setOnClickListener(this);
            }
        }
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.control_prev:
                // TODO
                break;

            case R.id.control_pauseplay:
                // TODO
                break;

            case R.id.control_next:
                // TODO
                break;
        }
        // Have any button click extend lockscreen's timeout.
        if (mCallback != null) {
            mCallback.userActivity(this);
        }
    }

}
+30 −2
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ import android.util.Log;
import android.util.TypedValue;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;
import android.view.View.MeasureSpec;


import com.android.internal.R;
import com.android.internal.R;


@@ -195,14 +196,41 @@ public class MultiWaveView extends View {
    protected int getSuggestedMinimumWidth() {
    protected int getSuggestedMinimumWidth() {
        // View should be large enough to contain the background + target drawable on either edge
        // View should be large enough to contain the background + target drawable on either edge
        return mOuterRing.getWidth()
        return mOuterRing.getWidth()
                + (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getWidth()) : 0);
                + (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getWidth()/2) : 0);
    }
    }


    @Override
    @Override
    protected int getSuggestedMinimumHeight() {
    protected int getSuggestedMinimumHeight() {
        // View should be large enough to contain the unlock ring + target drawable on either edge
        // View should be large enough to contain the unlock ring + target drawable on either edge
        return mOuterRing.getHeight()
        return mOuterRing.getHeight()
                + (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getHeight()) : 0);
                + (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getHeight()/2) : 0);
    }

    private int resolveMeasured(int measureSpec, int desired)
    {
        int result = 0;
        int specSize = MeasureSpec.getSize(measureSpec);
        switch (MeasureSpec.getMode(measureSpec)) {
            case MeasureSpec.UNSPECIFIED:
                result = desired;
                break;
            case MeasureSpec.AT_MOST:
                result = Math.min(specSize, desired);
                break;
            case MeasureSpec.EXACTLY:
            default:
                result = specSize;
        }
        return result;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int minimumWidth = getSuggestedMinimumWidth();
        final int minimumHeight = getSuggestedMinimumHeight();
        int viewWidth = resolveMeasured(widthMeasureSpec, minimumWidth);
        int viewHeight = resolveMeasured(heightMeasureSpec, minimumHeight);
        setMeasuredDimension(viewWidth, viewHeight);
    }
    }


    private void switchToState(int state, float x, float y) {
    private void switchToState(int state, float x, float y) {
Loading