summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2014-06-02 15:59:48 -0700
committerRicardo Cerqueira <ricardo@cyngn.com>2015-11-12 13:57:23 +0000
commitc82a981a36b9b14f8ea534243dbf3a1d2f7b2970 (patch)
treeab7019a4b0eb89f91c319552b74b6128f1e0bba2 /src
parente99158c230c2b84f982b94800cd36dd050206226 (diff)
downloadandroid_packages_apps_Screencast-c82a981a36b9b14f8ea534243dbf3a1d2f7b2970.tar.gz
android_packages_apps_Screencast-c82a981a36b9b14f8ea534243dbf3a1d2f7b2970.tar.bz2
android_packages_apps_Screencast-c82a981a36b9b14f8ea534243dbf3a1d2f7b2970.zip
Screencast: add stop button
When a user went back into the screencast app after starting a screencast, the UI would not reflect the recording status and would allow the user to start another recording, putting the app in a strange state. Now, we add a stop button which reflects the state. After starting the screencast, hide the activity. But if a user returns to the activity while recording, allow them to stop and start another recording. Change-Id: Ia549a04475cbddea84a2258e525ad55a22c4a0f2 Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/cyanogenmod/screencast/MainActivity.java52
-rw-r--r--src/com/cyanogenmod/screencast/ScreencastService.java4
2 files changed, 47 insertions, 9 deletions
diff --git a/src/com/cyanogenmod/screencast/MainActivity.java b/src/com/cyanogenmod/screencast/MainActivity.java
index d9cd640..843b8f9 100644
--- a/src/com/cyanogenmod/screencast/MainActivity.java
+++ b/src/com/cyanogenmod/screencast/MainActivity.java
@@ -20,26 +20,60 @@ import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
+import android.widget.Button;
public class MainActivity extends Activity {
- boolean mStarted;
+ Button mStartScreencastButton;
+ Button mStopScreencastButton;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- findViewById(R.id.start_screencast)
- .setOnClickListener(new View.OnClickListener() {
+ mStartScreencastButton = (Button) findViewById(R.id.start_screencast);
+ mStartScreencastButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (!mStarted) {
- mStarted = true;
- startService(new Intent("org.cyanogenmod.ACTION_START_SCREENCAST")
- .setClass(MainActivity.this, ScreencastService.class));
- finish();
- }
+ getSharedPreferences(ScreencastService.PREFS, 0).edit().putBoolean(ScreencastService.KEY_RECORDING, true).apply();
+ startService(new Intent("org.cyanogenmod.ACTION_START_SCREENCAST")
+ .setClass(MainActivity.this, ScreencastService.class));
+ finish();
}
});
+
+ mStopScreencastButton = (Button) findViewById(R.id.stop_screencast);
+ mStopScreencastButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getSharedPreferences(ScreencastService.PREFS, 0).edit().putBoolean(ScreencastService.KEY_RECORDING, false).apply();
+ startService(new Intent("org.cyanogenmod.ACTION_STOP_SCREENCAST")
+ .setClass(MainActivity.this, ScreencastService.class));
+ refreshState();
+ }
+ });
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ refreshState();
+ }
+
+ @Override
+ public void onWindowFocusChanged(boolean hasFocus) {
+ super.onWindowFocusChanged(hasFocus);
+ refreshState();
+ }
+
+ private void refreshState() {
+ final boolean recording = getSharedPreferences(ScreencastService.PREFS, 0).getBoolean(ScreencastService.KEY_RECORDING, false);
+ if (mStartScreencastButton != null) {
+ mStartScreencastButton.setEnabled(!recording);
+ }
+ if (mStopScreencastButton != null) {
+ mStopScreencastButton.setEnabled(recording);
+ }
}
}
diff --git a/src/com/cyanogenmod/screencast/ScreencastService.java b/src/com/cyanogenmod/screencast/ScreencastService.java
index c86fbe8..d703ea6 100644
--- a/src/com/cyanogenmod/screencast/ScreencastService.java
+++ b/src/com/cyanogenmod/screencast/ScreencastService.java
@@ -46,6 +46,8 @@ import java.util.TimerTask;
public class ScreencastService extends Service {
private static final String LOGTAG = "ScreencastService";
public static final String SCREENCASTER_NAME = "hidden:screen-recording";
+ public static final String PREFS = "preferences";
+ static final String KEY_RECORDING = "recording";
private long startTime;
private Timer timer;
private Notification.Builder mBuilder;
@@ -142,6 +144,7 @@ public class ScreencastService extends Service {
}
else if (intent != null && TextUtils.equals(intent.getAction(), "org.cyanogenmod.ACTION_START_SCREENCAST")) {
try {
+ getSharedPreferences(ScreencastService.PREFS, 0).edit().putBoolean(ScreencastService.KEY_RECORDING, true).apply();
if (!hasAvailableSpace()) {
Toast.makeText(this, R.string.not_enough_storage, Toast.LENGTH_LONG).show();
return START_STICKY;
@@ -169,6 +172,7 @@ public class ScreencastService extends Service {
}
else if (intent != null && TextUtils.equals(intent.getAction(), "org.cyanogenmod.ACTION_STOP_SCREENCAST")) {
try {
+ getSharedPreferences(ScreencastService.PREFS, 0).edit().putBoolean(ScreencastService.KEY_RECORDING, false).apply();
// clean show_touches settings if user enable show_touches in this activity
Settings.System.putInt(getContentResolver(), SHOW_TOUCHES, 0);
if (!hasAvailableSpace()) {