Skip to content

Commit

Permalink
permission check
Browse files Browse the repository at this point in the history
  • Loading branch information
msoner1 committed Feb 5, 2016
1 parent 3aaca42 commit 518c471
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
20 changes: 13 additions & 7 deletions library/src/main/java/org/firezenk/audiowaves/Visualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,29 @@ public class Visualizer extends LinearLayout implements IVisualizer {
public Visualizer(Context context) {
super(context);
this.context = context;
this.init();
if(!isInEditMode()) {
this.init();
}
}

public Visualizer(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;

this.attributes(attrs);
this.init();
if(!isInEditMode()){
this.attributes(attrs);
this.init();
}
}

public Visualizer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
public Visualizer(Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
this.context = context;

this.attributes(attrs);
this.init();
if(!isInEditMode()){
this.attributes(attrs);
this.init();
}
}

private void attributes(AttributeSet attrs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.firezenk.audiowaves.sample;

import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

Expand All @@ -9,12 +12,15 @@ public class MainActivity extends AppCompatActivity {

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
super.onResume();
((Visualizer) findViewById(R.id.visualizer)).startListening();
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
if(permissionCheck == PackageManager.PERMISSION_GRANTED) {
setContentView(R.layout.activity_main);
((Visualizer) findViewById(R.id.visualizer)).startListening();
}
else {
setContentView(R.layout.no_mic);
}
}

}
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
aw:aw_color_uniform="@color/red_light"
aw:aw_color_is_gradient="true"
aw:aw_color_gradient_start="@color/blue_light"
aw:aw_color_gradient_end="@color/red_light" />
aw:aw_color_gradient_end="@color/red_light"/>

</RelativeLayout>
15 changes: 15 additions & 0 deletions sample/src/main/res/layout/no_mic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Please grant access to the microphone"
android:gravity="center"
android:layout_margin="10dp"
android:id="@+id/textView"
android:layout_gravity="center_horizontal" />
</LinearLayout>

0 comments on commit 518c471

Please sign in to comment.