1.xml
/packages/SystemUI/res/layout/volume_panel_item.xml
+ <TextView
+ android:id="@+id/seek_bar_volume"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/status_bar_settings_airplane"
+ android:textSize="30sp" />
2.添加代码
frameworks/base/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
-// private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
+ private static boolean LOGD = true;
.......
private class StreamControl {
int streamType;
MediaController controller;
ViewGroup group;
ImageView icon;
SeekBar seekbarView;
TextView suppressorView;
View divider;
ImageView secondaryIcon;
int iconRes;
int iconMuteRes;
int iconSuppressedRes;
+ TextView seek_bar_volume;
}
.......
private void createSliders() {
final Resources res = mContext.getResources();
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
......
sc.group.findViewById(com.android.systemui.R.id.seekbar);
//add long
+ sc.seek_bar_volume = (TextView)sc.group.findViewById(com.android.systemui.R.id.seek_bar_volume);
//end long
.......
protected void onShowVolumeChanged(int streamType, int flags, MediaController controller) {
int index = getStreamVolume(streamType);
mRingIsSilent = false;
if (LOGD) {
Log.d(mTag, "onShowVolumeChanged(streamType: " + streamToString(streamType)
+ ", flags: " + flagsToString(flags) + "), index: " + index);
}
// get max volume for progress bar
int max = getStreamMaxVolume(streamType);
StreamControl sc = mStreamControls.get(streamType);
//add long
+ int vol=(index*100)/15;
+ sc.seek_bar_volume.setText(String.valueOf(vol));
//end long
3.全部文件
//frameworks/base/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
/*
* Copyright (C) 2007 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.systemui.volume;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioService;
import android.media.AudioSystem;
import android.media.RingtoneManager;
import android.media.ToneGenerator;
import android.media.VolumeProvider;
import android.media.session.MediaController;
import android.media.session.MediaController.PlaybackInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.android.internal.R;
import com.android.systemui.DemoMode;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.ZenModeController;
import java.io.FileDescriptor;
import java.io.PrintWriter;
/**
* Handles the user interface for the volume keys.
*
* @hide
*/
public class VolumePanel extends Handler implements DemoMode {
private static final String TAG = "VolumePanel";
//add long
// private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
private static boolean LOGD = true;
//end long
private static final int PLAY_SOUND_DELAY = AudioService.PLAY_SOUND_DELAY;
/**
* The delay before vibrating. This small period exists so if the user is
* moving to silent mode, it will not emit a short vibrate (it normally
* would since vibrate is between normal mode and silent mode using hardware
* keys).
*/
public static final int VIBRATE_DELAY = 300;
private static final int VIBRATE_DURATION = 300;
private static final int BEEP_DURATION = 150;
private static final int MAX_VOLUME = 100;
private static final int FREE_DELAY = 10000;
private static final int TIMEOUT_DELAY = 3000;
private static final int TIMEOUT_DELAY_SHORT = 1500;
private static final int TIMEOUT_DELAY_COLLAPSED = 4500;
private static final int TIMEOUT_DELAY_SAFETY_WARNING = 5000;
private static final int TIMEOUT_DELAY_EXPANDED = 10000;
private static final int MSG_VOLUME_CHANGED = 0;
private static final int MSG_FREE_RESOURCES = 1;
private static final int MSG_PLAY_SOUND = 2;
private static final int MSG_STOP_SOUNDS = 3;
private static final int MSG_VIBRATE = 4;
private static final int MSG_TIMEOUT = 5;
private static final int MSG_RINGER_MODE_CHANGED = 6;
private static final int MSG_MUTE_CHANGED = 7;
private static final int MSG_REMOTE_VOLUME_CHANGED = 8;
private static final int MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN = 9;
private static final int MSG_SLIDER_VISIBILITY_CHANGED = 10;
private static final int MSG_DISPLAY_SAFE_VOLUME_WARNING = 11;
private static final int MSG_LAYOUT_DIRECTION = 12;
private static final int MSG_ZEN_MODE_AVAILABLE_CHANGED = 13;
private static final int MSG_USER_ACTIVITY = 14;
private static final int MSG_NOTIFICATION_EFFECTS_SUPPRESSOR_CHANGED = 15;
private static final int MSG_INTERNAL_RINGER_MODE_CHANGED = 16;
// Pseudo stream type for master volume
private static final int STREAM_MASTER = -100;
// Pseudo stream type for remote volume
private static final int STREAM_REMOTE_MUSIC = -200;
private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
.build();
private static final int IC_AUDIO_VOL = com.android.systemui.R.drawable.ic_audio_vol;
private static final int IC_AUDIO_VOL_MUTE = com.android.systemui.R.drawable.ic_audio_vol_mute;
private static final int IC_AUDIO_BT = com.android.systemui.R.drawable.ic_audio_bt;
private static final int IC_AUDIO_BT_MUTE = com.android.systemui.R.drawable.ic_audio_bt_mute;
private final String mTag;
protected final Context mContext;
private final AudioManager mAudioManager;
private final ZenModeController mZenController;
private boolean mRingIsSilent;
private boolean mVoiceCapable;
private boolean mZenModeAvailable;
private boolean mZenPanelExpanded;
private int mTimeoutDelay = TIMEOUT_DELAY;
private float mDisabledAlpha;
private int mLastRingerMode = AudioManager.RINGER_MODE_NORMAL;
private int mLastRingerProgress = 0;
private int mDemoIcon;
// True if we want to play tones on the system stream when the master stream is specified.
private final boolean mPlayMasterStreamTones;
/** Volume panel content view */
private final View mView;
/** Dialog hosting the panel */
private final Dialog mDialog;
/** The visible portion of the volume overlay */
private final ViewGroup mPanel;
/** Contains the slider and its touchable icons */
private final ViewGroup mSliderPanel;
/** The zen mode configuration panel view */
private ZenModePanel mZenPanel;
/** The component currently suppressing notification stream effects */
private ComponentName mNotificationEffectsSuppressor;
private Callback mCallback;
/** Currently active stream that shows up at the top of the list of sliders */
private int mActiveStreamType = -1;
/** All the slider controls mapped by stream type */
private SparseArray<StreamControl> mStreamControls;
private final AccessibilityManager mAccessibilityManager;
private final SecondaryIconTransition mSecondaryIconTransition;
private final IconPulser mIconPulser;
private enum StreamResources {
BluetoothSCOStream(AudioManager.STREAM_BLUETOOTH_SCO,
R.string.volume_icon_description_bluetooth,
IC_AUDIO_BT,
IC_AUDIO_BT_MUTE,
false),
RingerStream(AudioManager.STREAM_RING,
R.string.volume_icon_description_ringer,
com.android.systemui.R.drawable.ic_ringer_audible,
com.android.systemui.R.drawable.ic_ringer_mute,
false),
VoiceStream(AudioManager.STREAM_VOICE_CALL,
R.string.volume_icon_description_incall,
com.android.systemui.R.drawable.ic_audio_phone,
com.android.systemui.R.drawable.ic_audio_phone,
false),
AlarmStream(AudioManager.STREAM_ALARM,
R.string.volume_alarm,
com.android.systemui.R.drawable.ic_audio_alarm,
com.android.systemui.R.drawable.ic_audio_alarm_mute,
false),
MediaStream(AudioManager.STREAM_MUSIC,
R.string.volume_icon_description_media,
IC_AUDIO_VOL,
IC_AUDIO_VOL_MUTE,
true),
NotificationStream(AudioManager.STREAM_NOTIFICATION,
R.string.volume_icon_description_notification,
com.android.systemui.R.drawable.ic_ringer_audible,
com.android.systemui.R.drawable.ic_ringer_mute,
true),
// for now, use media resources for master volume
MasterStream(STREAM_MASTER,
R.string.volume_icon_description_media, //FIXME should have its own description
IC_AUDIO_VOL,
IC_AUDIO_VOL_MUTE,
false),
RemoteStream(STREAM_REMOTE_MUSIC,
R.string.volume_icon_description_media, //FIXME should have its own description
com.android.systemui.R.drawable.ic_audio_remote,
com.android.systemui.R.drawable.ic_audio_remote,
false);// will be dynamically updated
int streamType;
int descRes;
int iconRes;
int iconMuteRes;
// RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested
boolean show;
StreamResources(int streamType, int descRes, int iconRes, int iconMuteRes, boolean show) {
this.streamType = streamType;
this.descRes = descRes;
this.iconRes = iconRes;
this.iconMuteRes = iconMuteRes;
this.show = show;
}
}
// List of stream types and their order
private static final StreamResources[] STREAMS = {
StreamResources.BluetoothSCOStream,
StreamResources.RingerStream,
StreamResources.VoiceStream,
StreamResources.MediaStream,
StreamResources.NotificationStream,
StreamResources.AlarmStream,
StreamResources.MasterStream,
StreamResources.RemoteStream
};
/** Object that contains data for each slider */
private class StreamControl {
int streamType;
MediaController controller;
ViewGroup group;
ImageView icon;
SeekBar seekbarView;
TextView suppressorView;
View divider;
ImageView secondaryIcon;
int iconRes;
int iconMuteRes;
int iconSuppressedRes;
//add long
TextView seek_bar_volume;
//end long
}
// Synchronize when accessing this
private ToneGenerator mToneGenerators[];
private Vibrator mVibrator;
private static int mDismissDelay;
private boolean mHasVibrator;
private static AlertDialog sSafetyWarning;
private static Object sSafetyWarningLock = new Object();
private static class SafetyWarning extends SystemUIDialog
implements DialogInterface.OnDismissListener, DialogInterface.OnClickListener {
private final Context mContext;
private final VolumePanel mVolumePanel;
private final AudioManager mAudioManag