-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve microphone sound threshold configuratoin UI/UX
- Loading branch information
Showing
7 changed files
with
266 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/main/java/info/guardianproject/phoneypot/ui/MicrophoneConfigureActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package info.guardianproject.phoneypot.ui; | ||
|
||
import android.os.Message; | ||
import android.os.RemoteException; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.Toolbar; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.NumberPicker; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import info.guardianproject.phoneypot.PreferenceManager; | ||
import info.guardianproject.phoneypot.R; | ||
import info.guardianproject.phoneypot.model.EventTrigger; | ||
import info.guardianproject.phoneypot.sensors.media.AudioRecorderTask; | ||
import info.guardianproject.phoneypot.sensors.media.MicSamplerTask; | ||
import info.guardianproject.phoneypot.sensors.media.MicrophoneTaskFactory; | ||
import me.angrybyte.numberpicker.view.ActualNumberPicker; | ||
|
||
import static info.guardianproject.phoneypot.R.id.microphone; | ||
|
||
public class MicrophoneConfigureActivity extends AppCompatActivity implements MicSamplerTask.MicListener { | ||
|
||
private MicSamplerTask microphone; | ||
private TextView mTextLevel; | ||
private ActualNumberPicker mNumberTrigger; | ||
private PreferenceManager mPrefManager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_microphone_configure); | ||
|
||
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
setTitle("Sound Sensitivity"); | ||
|
||
mTextLevel = (TextView)findViewById(R.id.text_display_level); | ||
mNumberTrigger = (ActualNumberPicker)findViewById(R.id.number_trigger_level); | ||
|
||
mNumberTrigger.setMinValue(0); | ||
mNumberTrigger.setMaxValue(120); | ||
|
||
mPrefManager = new PreferenceManager(this.getApplicationContext()); | ||
|
||
if (mPrefManager.getMicrophoneSensitivity().equals("High")) { | ||
mNumberTrigger.setValue(40); | ||
} else if (mPrefManager.getMicrophoneSensitivity().equals("Medium")) { | ||
mNumberTrigger.setValue(60); | ||
} | ||
else | ||
{ | ||
try { | ||
//maybe it is a threshold value? | ||
mNumberTrigger.setValue(Integer.parseInt(mPrefManager.getMicrophoneSensitivity())); | ||
} | ||
catch (Exception e){} | ||
} | ||
|
||
startMic(); | ||
} | ||
|
||
private void startMic () | ||
{ | ||
try { | ||
microphone = MicrophoneTaskFactory.makeSampler(this); | ||
microphone.setMicListener(this); | ||
microphone.execute(); | ||
} catch (MicrophoneTaskFactory.RecordLimitExceeded e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
|
||
if (microphone != null) | ||
microphone.cancel(true); | ||
|
||
mPrefManager.setMicrophoneSensitivity(mNumberTrigger.getValue()+""); | ||
} | ||
|
||
@Override | ||
public void onSignalReceived(short[] signal) { | ||
/* | ||
* We do and average of the 512 samples | ||
*/ | ||
int total = 0; | ||
int count = 0; | ||
for (short peak : signal) { | ||
//Log.i("MicrophoneFragment", "Sampled values are: "+peak); | ||
if (peak != 0) { | ||
total += Math.abs(peak); | ||
count++; | ||
} | ||
} | ||
// Log.i("MicrophoneFragment", "Total value: " + total); | ||
int average = 0; | ||
if (count > 0) average = total / count; | ||
/* | ||
* We compute a value in decibels | ||
*/ | ||
double averageDB = 0.0; | ||
if (average != 0) { | ||
averageDB = 20 * Math.log10(Math.abs(average) / 1); | ||
} | ||
|
||
mTextLevel.setText(((int)averageDB)+""); | ||
|
||
if (averageDB > mNumberTrigger.getValue()) | ||
{ | ||
Toast.makeText(this,"Sound Threshold Crossed!",Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onMicError() { | ||
|
||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.monitor_start, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected (MenuItem item) { | ||
switch (item.getItemId()){ | ||
case R.id.menu_save: | ||
finish(); | ||
break; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
android:theme="@style/AppTheme.AppBarOverlay"/> | ||
app:popupTheme="@style/AppTheme.PopupOverlay" /> | ||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
> | ||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:text="Current Audio Level" | ||
/> | ||
<TextView | ||
android:id="@+id/text_display_level" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:textSize="80dp" | ||
android:text="0" | ||
/> | ||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:text="Configure Trigger Level" | ||
android:layout_marginTop="15dp" | ||
/> | ||
|
||
<me.angrybyte.numberpicker.view.ActualNumberPicker | ||
android:id="@+id/number_trigger_level" | ||
android:layout_width="match_parent" | ||
android:layout_height="48dp" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="3dp" | ||
android:background="#FFFFFFFF" | ||
app:bar_color="@android:color/darker_gray" | ||
app:bar_width="1dp" | ||
app:draw_over_controls="true" | ||
app:max_value="100" | ||
app:min_value="0" | ||
app:show_text="true" | ||
app:show_bars="true" | ||
app:show_controls="false" | ||
app:show_fast_controls="false" | ||
app:text_color="@android:color/darker_gray" | ||
app:text_size="16sp" /> | ||
|
||
</LinearLayout> | ||
</ScrollView> | ||
</LinearLayout> |
Oops, something went wrong.