diff options
author | Ricardo Cerqueira <ricardo@cyngn.com> | 2016-01-22 19:55:11 +0000 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2016-02-10 23:15:46 -0800 |
commit | 82f991cc1f218eeef9454b2e20ef80275c3da269 (patch) | |
tree | 46f4d79afe04a03b8f20b820981b4dfef845f79b | |
parent | 4ffc37c05c1c3318f5292079e25a29f26ebda8db (diff) | |
download | android_packages_apps_Screencast-82f991cc1f218eeef9454b2e20ef80275c3da269.tar.gz android_packages_apps_Screencast-82f991cc1f218eeef9454b2e20ef80275c3da269.tar.bz2 android_packages_apps_Screencast-82f991cc1f218eeef9454b2e20ef80275c3da269.zip |
Fix up audio recording
AUDIO_RECORD is a runtime permission, ask for it.
We're intentionally letting the activity proceed even if the permission
gets denied. People may not want audio.
The app will display an informational warning and a shortcut to the app
permissions when audio is disable so users know why they are not getting
audio, and how to enable it.
CYNGNOS-1695
Change-Id: Ic535fedcd666d929bc5eabe068817eff1275967e
-rw-r--r-- | AndroidManifest.xml | 2 | ||||
-rw-r--r-- | res/layout/main.xml | 19 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/org/cyanogenmod/screencast/MainActivity.java | 82 |
4 files changed, 104 insertions, 2 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 03499b2..52cb98b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,7 +5,7 @@ android:versionName="1.0.0.3"> <uses-sdk - android:minSdkVersion="21" + android:minSdkVersion="23" android:targetSdkVersion="23" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> diff --git a/res/layout/main.xml b/res/layout/main.xml index 7842d20..7a73579 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -9,11 +9,22 @@ <TextView style="@android:style/TextAppearance.Medium" + android:id="@+id/start_description" android:gravity="center" android:text="@string/start_description" android:layout_width="wrap_content" android:layout_height="wrap_content"/> + <TextView + style="@android:style/TextAppearance.Medium" + android:id="@+id/no_audio_warning" + android:gravity="center" + android:text="@string/no_audio_warning" + android:layout_marginTop="10dp" + android:visibility="gone" + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" @@ -22,6 +33,13 @@ android:orientation="vertical" > <Button + android:id="@+id/settings" + android:text="@string/settings" + android:visibility="gone" + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + + <Button android:id="@+id/start_screencast" android:text="@string/start_screencast" android:layout_width="wrap_content" @@ -33,6 +51,7 @@ android:enabled="false" android:layout_width="wrap_content" android:layout_height="wrap_content"/> + </LinearLayout> </LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml index b9ce154..62b09f6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -26,4 +26,7 @@ <string name="not_enough_storage">Not enough storage available</string> <string name="start_screencast">Start Screencast</string> <string name="start_description">Press \"Start Screencast\" to begin recording a video of your Android screen and microphone.</string> + <string name="start_description_no_audio">Press \"Start Screencast\" to begin recording a video of your Android screen.</string> + <string name="no_audio_warning">To include audio, go to Settings and enable the microphone permission for this app.</string> + <string name="settings">Settings</string> </resources> diff --git a/src/org/cyanogenmod/screencast/MainActivity.java b/src/org/cyanogenmod/screencast/MainActivity.java index 843b8f9..63f1c68 100644 --- a/src/org/cyanogenmod/screencast/MainActivity.java +++ b/src/org/cyanogenmod/screencast/MainActivity.java @@ -16,22 +16,67 @@ package org.cyanogenmod.screencast; +import android.Manifest; import android.app.Activity; import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.Uri; import android.os.Bundle; +import android.provider.Settings; import android.view.View; import android.widget.Button; +import android.widget.TextView; public class MainActivity extends Activity { Button mStartScreencastButton; Button mStopScreencastButton; + Button mSettingsButton; + TextView mStartDescription; + View mNoAudioWarning; + + boolean mHasAudioPermission = false; + + private static final int REQUEST_AUDIO_PERMS = 654; + + private boolean hasPermissions() { + int res = checkCallingOrSelfPermission(Manifest.permission.RECORD_AUDIO); + return (res == PackageManager.PERMISSION_GRANTED); + } + + private void requestNecessaryPermissions() { + String[] permissions = new String[] { + Manifest.permission.RECORD_AUDIO, + }; + requestPermissions(permissions, REQUEST_AUDIO_PERMS); + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, + int[] grantResults) { + if (requestCode == REQUEST_AUDIO_PERMS) { + mHasAudioPermission = true; + for (int res : grantResults) { + mHasAudioPermission &= (res == PackageManager.PERMISSION_GRANTED); + } + refreshState(); + } + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); + if (!hasPermissions()) { + requestNecessaryPermissions(); + } else { + mHasAudioPermission = true; + } + + mStartDescription = (TextView) findViewById(R.id.start_description); + mNoAudioWarning = findViewById(R.id.no_audio_warning); + mStartScreencastButton = (Button) findViewById(R.id.start_screencast); mStartScreencastButton.setOnClickListener(new View.OnClickListener() { @Override @@ -53,11 +98,20 @@ public class MainActivity extends Activity { refreshState(); } }); + + mSettingsButton = (Button) findViewById(R.id.settings); + mSettingsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + goToSettings(); + } + }); } @Override protected void onResume() { super.onResume(); + mHasAudioPermission = hasPermissions(); refreshState(); } @@ -75,5 +129,31 @@ public class MainActivity extends Activity { if (mStopScreencastButton != null) { mStopScreencastButton.setEnabled(recording); } + + int visibility = mHasAudioPermission ? View.GONE : View.VISIBLE; + if (mSettingsButton != null) { + mSettingsButton.setVisibility(visibility); + } + if (mNoAudioWarning != null) { + mNoAudioWarning.setVisibility(visibility); + } + + if (mStartDescription != null) { + mStartDescription.setText( + mHasAudioPermission + ? R.string.start_description + : R.string.start_description_no_audio + ); + } + } + + private void goToSettings() { + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setData(Uri.parse("package:" + getPackageName())); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + startActivity(intent); } -} +}
\ No newline at end of file |