Android 分贝测试仪功能,挥泪整理面经
android:layout_margin=“5dp”
android:background="@drawable/record_wave_right" />
<ScrollView
android:id="@+id/absclv"
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_below="@id/rl"
android:focusable=“false”
android:focusableInTouchMode=“true”
android:background="@android:color/white">
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“horizontal”
android:padding=“10dp”>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“10dB”
android:textColor="@android:color/holo_green_light"
android:textSize=“20dp”
android:textStyle=“bold” />
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginLeft=“10dp”
android:text=“呼吸声”
android:textColor="@android:color/darker_gray"
android:textSize=“20sp”/>
<View
android:layout_width=“wrap_content”
android:layout_height=“1dp”
android:background="@android:color/darker_gray"/>
。。。。
分贝值旁边的两个小喇叭是有动画效果的animation-list
接下来是 MicDemoActivity 完成开启麦克风接收音量功能
package com.rikka.toolbox;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
public class MicDemoActivity extends Activity {
private MicroPhoneThread microPhone = new MicroPhoneThread(); //线程用于实时录制周围声音
public boolean istrue = true;
private MediaRecorder mARecorder; //麦克风控制
private File mAudiofile,mSampleDir; //录音文件保存
private ImageView iv_record_wave_left,iv_record_wave_right;
private AnimationDrawable ad_left,ad_right;
private TextView textView1;
private MHandler mHandler = new MHandler();
class MHandler extends Handler{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 1:
textView1.setText(msg.obj.toString());
}
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_mic);
init();
}
private void init() {
//初始化左侧动态动画控件
iv_record_wave_left = findViewById(R.id.iv_record_wave_left);
iv_recor
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
d_wave_right = findViewById(R.id.iv_record_wave_right);
ad_left = (AnimationDrawable) iv_record_wave_left.getBackground();
ad_right = (AnimationDrawable) iv_record_wave_right.getBackground();
ad_left.start();
ad_right.start();
textView1 = findViewById(R.id.textView1);
}
@Override
protected void onStart() {
super.onStart();
//录音获取麦克风声音
mARecorder = new MediaRecorder(); //声音录制
mARecorder.setAudioSource(MediaRecorder.AudioSource.MIC); //录制的音源为麦克风
mARecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); //设置音频文件的编码
mARecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //设置audio格式
try{
mSampleDir = Environment.getExternalStorageDirectory(); //获取手机内存路径
//用IM+系统当前时间为文件名建立.amr的文件,文件路径为mSampleDir
mAudiofile = File.createTempFile(“IM” + System.currentTimeMillis(),".amr",mSampleDir);
} catch (IOException e) {
Log.e(“IMMESSAGE”,“sdcard access error”);
}
mARecorder.setOutputFile(mAudiofile.getAbsolutePath()); //设置路径
try{
mARecorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mARecorder.start();
microPhone.start();
}
//返回功能
public void onBack(View v){
MicDemoActivity.this.finish();
}
class MicroPhoneThread extends Thread{ //测试当前分贝值通知UI修改
final float minAngle = (float) Math.PI * 4 / 11;
float angle;
@Override
public void run() {
while(istrue){
angle = 100 * minAngle * mARecorder.getMaxAmplitude() / 32768;
if(angle > 100){
angle = 100;
}
//构造方法的字符格式这里如果小数不足2位,会已0补足
DecimalFormat decimalFormat = new DecimalFormat(“0.00”);
String p = decimalFormat.format(angle);
mHandler.sendMessage(mHandler.obtainMessage(1,p));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Android 分贝测试仪功能,挥泪整理面经相关推荐
- Android 分贝测试仪功能,你会的还只有初级Android工程师的技术吗
android:textSize="40sp" android:textStyle="bold"/> <ImageView android:id=& ...
- 疯狂涨知识!拥有百万粉丝的大牛讲述学Android的历程,挥泪整理面经
开头 每到"金三银四"的季节,总人很多人去寻找名叫"面经"一样的东西,其实就是一个个具体的题目,然后临阵磨枪,去"背"答案,如果一直是这样的 ...
- Android UI 设计规范,挥泪整理面经
** 底部动作条(Bottom Sheets) ** 底部动作条是一个从屏幕底部边缘向上滑出的一个面板,使用这种方式向用户呈现一组功能.底部动作条呈现了简单.清晰.无需额外解释的一组操作. 通常以列表 ...
- android 功能清单文件夹,全新Android L大小全部功能清单整理
今天凌晨,谷歌在美国旧金山发布全新安卓系统 Android L,该系统预计今年秋季发布,在此之前先向开发者提供. 在凌晨的主题演讲中,谷歌表示全新安卓系统将为用户提供全新的使用体验,比如 Projec ...
- android倒计时功能,android实现倒计时功能(开始、暂停、0秒结束)
本文实例为大家分享了android实现倒计时功能的具体代码,供大家参考,具体内容如下 [思路]:通过 timer 执行周期延时的任务,handler 中将计时信息更新,并在计时结束时结束 timer ...
- 荷包app软件测试,智能分贝测试仪app
智能分贝测试仪app 智能分贝测试仪app是一款可以通过手机麦克风对周边环境噪音进行检测评估的软件,检测完成之后,会为用户显示当前的环境噪音分贝值,还可以根据用户的定位设置,来判定,当前的噪音水平对于 ...
- Android开源项目及库整理总结
自己总结的Android开源项目及库. github排名https://github.com/trending, github搜索:https://github.com/search UI Aweso ...
- 【我的Android进阶之旅】Android 混淆文件资源分类整理之二:将混淆文件拆分成更小粒度的混淆文件
在我2017年的文章[我的Android进阶之旅]Android 混淆文件资源分类整理中,我已经提及过. 之前将所有的混淆都配置在一个 proguard-rules.pro 这个Android Stu ...
- Android 常用开发功能 博客导航
转载地址:http://blog.csdn.net/ciqing123/article/details/52931663?locationNum=16&fps=1 简介:第一次在CSDN上发表 ...
- Android 笔试/面试,常见问题整理
Android 笔试/面试,常见问题整理 Android学习书籍下载的网址:http://pan.baidu.com/s/1slCSUcP 上面网盘里面的书籍都是PDF格式的,有面试宝典,疯狂java ...
最新文章
- 英特尔2022年投资者大会:公布技术路线图及重要节点
- 用 Python 和 OpenCV 检测图片上的条形码Detecting Barcodes in Images with Python and OpenCV
- Go(GoLang)解决 cannot find package/golang.org/问题 Grpc+ProtoBuf所需的一些资源
- CVPR2015深度学习回顾
- RED5 安装及问题
- 虚拟机安装Linux(vmware + ubuntu)
- Python找出某元素的索引下标
- Java泛型初探————泛型通配
- Visual C++ 基础数据类型的转换
- PowerDesigner(七)-数据库的生成和修改
- 2022牛客寒假算法基础集训营1 签到题7题
- Ros简单程序编写及使用类Hello World
- 为什么选择springcloud作为微服务架构
- Oracle数据库阶段版本
- 《东周列国志》第五十四回 荀林父纵属亡师 孟侏儒托优悟主
- 通过js批量下载地图TopoJson数据
- 案例 | 巴别鸟为弘睿构建企业知识库
- 店铺差评有什么影响原因有哪些方面,怎么避免差评,被差评了怎么解决
- 第四届橙瓜网络文学奖网文之王,烽火戏诸侯舍我其谁?
- 小米手机用什么耳机音质好?发烧级音质蓝牙耳机推荐