Skip to content

Commit 4258dca

Browse files
author
CodingForAndroid
committed
add volume button
1 parent eb406dd commit 4258dca

7 files changed

Lines changed: 73 additions & 7 deletions

File tree

app/src/main/java/com/bczm/widgetcollections/http/protocol/VideoDetailProtocol.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public class VideoDetailProtocol {
3030

3131

3232
//获取 猜你喜欢
33-
public List<GuessFavoriteBean> getGuessFavorite() {
33+
public List<GuessFavoriteBean> getGuessFavorite() {
3434

3535
List<GuessFavoriteBean> list = null;
3636
try {
37-
list = new ArrayList<GuessFavoriteBean>();
37+
list = new ArrayList<>();
3838
JSONObject jsonObject = new JSONObject(ConfigManage.GUESS_FAVOURIATE);
3939
JSONArray jsonArray = (JSONArray) jsonObject.opt("items");
4040
JsonHelper.JSONArrayToList(jsonArray, list, GuessFavoriteBean.class);
@@ -47,7 +47,7 @@ public List<GuessFavoriteBean> getGuessFavorite() {
4747
//获取 猜你喜欢
4848
public GuessFavoriteBean[] getGuessFavoriteArray() {
4949
try {
50-
List<GuessFavoriteBean> list = new ArrayList<GuessFavoriteBean>();
50+
List<GuessFavoriteBean> list = new ArrayList<>();
5151
JSONObject jsonObject = new JSONObject(ConfigManage.GUESS_FAVOURIATE);
5252
JSONArray jsonArray = (JSONArray) jsonObject.opt("items");
5353
JsonHelper.JSONArrayToList(jsonArray, list, GuessFavoriteBean.class);

app/src/main/java/com/bczm/widgetcollections/ui/activity/SplashActivity.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import android.os.Bundle;
77
import android.view.KeyEvent;
88
import android.view.View;
9+
import android.widget.ImageButton;
910
import android.widget.ImageView;
1011
import android.widget.RelativeLayout;
12+
import android.widget.TextView;
1113
import android.widget.VideoView;
1214

1315
import com.bczm.widgetcollections.R;
1416
import com.bczm.widgetcollections.http.ConfigManage;
17+
import com.bczm.widgetcollections.utils.SystemUtils;
1518
import com.bczm.widgetcollections.utils.UIUtils;
1619

1720
import butterknife.Bind;
@@ -25,9 +28,11 @@
2528
public class SplashActivity extends BaseActivity implements MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener {
2629
@Bind(R.id.videoView)
2730
VideoView videoView;
31+
@Bind(R.id.ic_music_on)
32+
ImageView ivMusic;
2833
@Bind(R.id.iv_close)
29-
ImageView ivClose;
30-
34+
TextView ivClose;
35+
public boolean slince=true;
3136
@Override
3237
protected void createContent() {
3338
setContentView(R.layout.activity_splash);
@@ -64,6 +69,20 @@ public void onClick(View view) {
6469
goToMainActivity();
6570
}
6671
});
72+
73+
ivMusic.setOnClickListener(new View.OnClickListener() {
74+
@Override
75+
public void onClick(View view) {// 是否静音
76+
if(slince){
77+
slince=false;
78+
SystemUtils.setVolumeSilence();
79+
}else{
80+
slince=true;
81+
SystemUtils.setVolumeNormal();
82+
}
83+
84+
}
85+
});
6786
}
6887

6988
@Override
@@ -91,6 +110,7 @@ public void goToMainActivity(){
91110
Intent intent = new Intent(this, MainActivity.class);
92111
UIUtils.startActivity(intent);
93112
// startActivity(intent);
113+
SystemUtils.setVolumeNormal();
94114
finish();
95115
}
96116

app/src/main/java/com/bczm/widgetcollections/utils/SystemUtils.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.app.ActivityManager;
55
import android.content.Context;
66
import android.content.pm.PackageManager;
7+
import android.media.AudioManager;
78
import android.net.wifi.WifiInfo;
89
import android.net.wifi.WifiManager;
910
import android.os.Debug;
@@ -553,4 +554,36 @@ public static boolean isLowMemory() {
553554
activityManager.getMemoryInfo(info);
554555
return info.lowMemory;
555556
}
557+
558+
/**
559+
* 设置播放静音
560+
*/
561+
public static void setVolumeSilence(){
562+
Context context = UIUtils.getContext();
563+
if (context == null) {
564+
return ;
565+
}
566+
//音量控制,初始化定义
567+
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
568+
mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
569+
////最大音量
570+
// int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
571+
////当前音量
572+
// int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
573+
574+
575+
}
576+
577+
/**
578+
* 取消静音
579+
*/
580+
public static void setVolumeNormal(){
581+
Context context = UIUtils.getContext();
582+
if (context == null) {
583+
return ;
584+
}
585+
//音量控制,初始化定义
586+
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
587+
mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
588+
}
556589
}

app/src/main/res/layout/activity_splash.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@
77
android:layout_height="fill_parent"
88
android:layout_centerInParent="true"/>
99
<ImageView
10+
android:scaleType="center"
11+
android:background="@mipmap/ic_welcome_skip_bg"
12+
android:layout_margin="30dp"
13+
android:id="@+id/ic_music_on"
14+
android:src="@mipmap/ic_music_on"
15+
android:layout_width="30dp"
16+
android:layout_alignParentRight="true"
17+
android:layout_alignParentTop="true"
18+
android:layout_height="30dp" />
19+
<TextView
20+
android:gravity="center"
1021
android:layout_margin="30dp"
1122
android:id="@+id/iv_close"
12-
android:src="@mipmap/search_cancel"
23+
android:background="@mipmap/poi_comment_tag_select"
24+
android:text="跳过"
1325
android:layout_width="wrap_content"
14-
android:layout_alignParentRight="true"
26+
android:layout_alignParentLeft="true"
1527
android:layout_alignParentTop="true"
1628
android:layout_height="wrap_content" />
29+
1730
</RelativeLayout>
526 Bytes
Loading
1.04 KB
Loading
1.09 KB
Loading

0 commit comments

Comments
 (0)