Skip to content

Commit

Permalink
Merge branch 'patch-showtouches' of https://github.com/monxalo/Telecine
Browse files Browse the repository at this point in the history
… into monxalo-patch-showtouches
  • Loading branch information
JakeWharton committed Jul 14, 2015
2 parents 3e18e50 + c5393be commit 4a77ca1
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions telecine/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Analytics {
String ACTION_CHANGE_SHOW_COUNTDOWN = "Show Countdown";
String ACTION_CHANGE_HIDE_RECENTS = "Hide In Recents";
String ACTION_CHANGE_RECORDING_NOTIFICATION = "Recording Notification";
String ACTION_CHANGE_SHOW_TOUCHES = "Show Touches";
String ACTION_OVERLAY_SHOW = "Overlay Show";
String ACTION_OVERLAY_HIDE = "Overlay Hide";
String ACTION_OVERLAY_CANCEL = "Overlay Cancel";
Expand Down
11 changes: 11 additions & 0 deletions telecine/src/main/java/com/jakewharton/telecine/ShowTouches.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jakewharton.telecine;

import java.lang.annotation.Retention;
import javax.inject.Qualifier;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Qualifier
@Retention(RUNTIME)
@interface ShowTouches {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public final class TelecineActivity extends Activity {
@InjectView(R.id.switch_show_countdown) Switch showCountdownView;
@InjectView(R.id.switch_hide_from_recents) Switch hideFromRecentsView;
@InjectView(R.id.switch_recording_notification) Switch recordingNotificationView;
@InjectView(R.id.switch_show_touches) Switch showTouchesView;

@Inject @VideoSizePercentage IntPreference videoSizePreference;
@Inject @ShowCountdown BooleanPreference showCountdownPreference;
@Inject @HideFromRecents BooleanPreference hideFromRecentsPreference;
@Inject @RecordingNotification BooleanPreference recordingNotificationPreference;
@Inject @ShowTouches BooleanPreference showTouchesPreference;

@Inject Analytics analytics;

Expand Down Expand Up @@ -58,6 +60,7 @@ public final class TelecineActivity extends Activity {
showCountdownView.setChecked(showCountdownPreference.get());
hideFromRecentsView.setChecked(hideFromRecentsPreference.get());
recordingNotificationView.setChecked(recordingNotificationPreference.get());
showTouchesView.setChecked(showTouchesPreference.get());
}

@OnClick(R.id.launch) void onLaunchClicked() {
Expand Down Expand Up @@ -139,6 +142,21 @@ public final class TelecineActivity extends Activity {
}
}

@OnCheckedChanged(R.id.switch_show_touches) void onShowTouchesChanged() {
boolean newValue = showTouchesView.isChecked();
boolean oldValue = showTouchesPreference.get();
if (newValue != oldValue) {
Timber.d("Show touches preference changing to %s", newValue);
showTouchesPreference.set(newValue);

analytics.send(new HitBuilders.EventBuilder() //
.setCategory(Analytics.CATEGORY_SETTINGS)
.setAction(Analytics.ACTION_CHANGE_SHOW_TOUCHES)
.setValue(newValue ? 1 : 0)
.build());
}
}

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!CaptureHelper.handleActivityResult(this, requestCode, resultCode, data, analytics)) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jakewharton.telecine;

import android.content.ContentResolver;
import android.content.SharedPreferences;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
Expand All @@ -21,6 +22,7 @@ final class TelecineModule {
private static final String PREFERENCES_NAME = "telecine";
private static final boolean DEFAULT_SHOW_COUNTDOWN = true;
private static final boolean DEFAULT_HIDE_FROM_RECENTS = false;
private static final boolean DEFAULT_SHOW_TOUCHES = false;
private static final boolean DEFAULT_RECORDING_NOTIFICATION = false;
private static final int DEFAULT_VIDEO_SIZE_PERCENTAGE = 100;

Expand All @@ -45,6 +47,10 @@ final class TelecineModule {
return new Analytics.GoogleAnalytics(tracker);
}

@Provides @Singleton ContentResolver provideContentResolver() {
return app.getContentResolver();
}

@Provides @Singleton SharedPreferences provideSharedPreferences() {
return app.getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE);
}
Expand Down Expand Up @@ -73,6 +79,15 @@ BooleanPreference provideRecordingNotificationPreference(SharedPreferences prefs
return new BooleanPreference(prefs, "hide-from-recents", DEFAULT_HIDE_FROM_RECENTS);
}

@Provides @Singleton @ShowTouches BooleanPreference provideShowTouchesPreference(
SharedPreferences prefs) {
return new BooleanPreference(prefs, "show-touches", DEFAULT_SHOW_TOUCHES);
}

@Provides @ShowTouches Boolean provideShowTouches(@ShowTouches BooleanPreference pref) {
return pref.get();
}

@Provides @Singleton @VideoSizePercentage IntPreference provideVideoSizePercentagePreference(
SharedPreferences prefs) {
return new IntPreference(prefs, "video-size", DEFAULT_VIDEO_SIZE_PERCENTAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import android.app.Notification;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.provider.Settings;
import android.support.annotation.NonNull;
import javax.inject.Inject;
import javax.inject.Provider;
Expand All @@ -16,6 +18,7 @@ public final class TelecineService extends Service {
private static final String EXTRA_RESULT_CODE = "result-code";
private static final String EXTRA_DATA = "data";
private static final int NOTIFICATION_ID = 99118822;
private static final String SHOW_TOUCHES = "show_touches";

public static Intent newIntent(Context context, int resultCode, Intent data) {
Intent intent = new Intent(context, TelecineService.class);
Expand All @@ -27,14 +30,20 @@ public static Intent newIntent(Context context, int resultCode, Intent data) {
@Inject @ShowCountdown Provider<Boolean> showCountdownProvider;
@Inject @VideoSizePercentage Provider<Integer> videoSizePercentageProvider;
@Inject @RecordingNotification Provider<Boolean> recordingNotificationProvider;
@Inject @ShowTouches Provider<Boolean> showTouchesProvider;

@Inject Analytics analytics;
@Inject ContentResolver contentResolver;

private boolean running;
private RecordingSession recordingSession;

private final RecordingSession.Listener listener = new RecordingSession.Listener() {
@Override public void onStart() {
if (showTouchesProvider.get()) {
Settings.System.putInt(contentResolver, SHOW_TOUCHES, 1);
}

if (!recordingNotificationProvider.get()) {
return; // No running notification was requested.
}
Expand All @@ -56,6 +65,10 @@ public static Intent newIntent(Context context, int resultCode, Intent data) {
}

@Override public void onStop() {
if (showTouchesProvider.get()) {
Settings.System.putInt(contentResolver, SHOW_TOUCHES, 0);
}

stopForeground(true /* remove notification */);
}

Expand Down
21 changes: 20 additions & 1 deletion telecine/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@
/>
</LinearLayout>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/show_touches"
android:textAlignment="viewStart"
/>
<Switch
android:id="@+id/switch_show_touches"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

</LinearLayout>
</ScrollView>
1 change: 1 addition & 0 deletions telecine/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="notification_recording_title">Recording screen.</string>
<string name="notification_recording_subtitle">Touch the clock area to stop recording.</string>
<string name="recording_notification">Recording Notification</string>
<string name="show_touches">Show Touches</string>

<array name="countdown">
<item>@string/countdown_three</item>
Expand Down

0 comments on commit 4a77ca1

Please sign in to comment.