summaryrefslogtreecommitdiffstats
path: root/AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java
diff options
context:
space:
mode:
authorShawn Alty <shawn.alty@gmail.com>2011-12-27 21:22:49 -0600
committerShawn Alty <shawn.alty@gmail.com>2011-12-27 21:22:49 -0600
commitc5a2454a28e87a779873c369053078e7cc81c663 (patch)
treeea2efe4375597a21e66deeca2e014f6dd4a7297d /AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java
parent8e76d3645d1d41511e82d4554e49444c51049b22 (diff)
downloaddevice_samsung_aries-common-c5a2454a28e87a779873c369053078e7cc81c663.zip
device_samsung_aries-common-c5a2454a28e87a779873c369053078e7cc81c663.tar.gz
device_samsung_aries-common-c5a2454a28e87a779873c369053078e7cc81c663.tar.bz2
Mass rename of com.cyanogenmod.AriesParts to com.cyanogenmod.settings.device
Needed (possibly?) for "Device Settings" to work.
Diffstat (limited to 'AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java')
-rw-r--r--AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java146
1 files changed, 146 insertions, 0 deletions
diff --git a/AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java b/AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java
new file mode 100644
index 0000000..5392669
--- /dev/null
+++ b/AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java
@@ -0,0 +1,146 @@
+package com.cyanogenmod.settings.device;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.hardware.TvOut;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+import android.preference.PreferenceManager;
+import android.view.Display;
+import android.view.IRotationWatcher;
+import android.view.IWindowManager;
+import android.view.WindowManager;
+
+public class TvOutService extends Service {
+
+ public static final String EXTRA_COMMAND = "command";
+ public static final String EXTRA_SYSTEM = "system";
+ public static final String COMMAND_ENABLE = "enable";
+ public static final String COMMAND_DISABLE = "disable";
+ public static final String COMMAND_CHANGE_SYSTEM = "system";
+
+ private TvOut mTvOut;
+ private SharedPreferences mPref;
+ private int mSystem;
+ private boolean mWasOn = false; // For enabling on screen on
+
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (Intent.ACTION_HEADSET_PLUG.equals(action)) {
+ int state = intent.getIntExtra("state", 0);
+ if (state == 0 && mTvOut._isEnabled()) {
+ // Disable when cable is unplugged
+ mWasOn = false;
+ disable();
+ stopSelf();
+ }
+ }
+ else if (Intent.ACTION_SCREEN_ON.equals(action)) {
+ if (mWasOn) {
+ enable();
+ mWasOn = false;
+ }
+ }
+ else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
+ if (mTvOut._isEnabled()) {
+ mWasOn = true;
+ disable();
+ }
+ }
+ }
+
+ };
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public void onCreate() {
+ mTvOut = new TvOut();
+ mPref = PreferenceManager.getDefaultSharedPreferences(this);
+
+ IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
+ try {
+ wm.watchRotation(new IRotationWatcher.Stub() {
+ @Override
+ public void onRotationChanged(int rotation) {
+ TvOutService.this.onRotationChanged(rotation);
+ }
+ });
+ }
+ catch (RemoteException e) { }
+
+ IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
+ filter.addAction(Intent.ACTION_SCREEN_OFF);
+ filter.addAction(Intent.ACTION_SCREEN_ON);
+ registerReceiver(mReceiver, filter);
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent != null) {
+ String command = intent.getStringExtra("command");
+ if (COMMAND_ENABLE.equals(command)) {
+ mSystem = Integer.parseInt(mPref.getString(AriesParts.KEY_TVOUT_SYSTEM, "2")); // Default = PAL
+ enable();
+ }
+ else if (COMMAND_DISABLE.equals(command)) {
+ disable();
+ stopSelf();
+ }
+ else if (COMMAND_CHANGE_SYSTEM.equals(command)) {
+ if (mTvOut._isEnabled()) {
+ mSystem = intent.getIntExtra(EXTRA_SYSTEM, 2);
+ disable();
+ enable();
+ }
+ }
+ }
+
+ return START_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ unregisterReceiver(mReceiver);
+ mTvOut.finalize();
+ super.onDestroy();
+ }
+
+ public void onRotationChanged(int rotation) {
+ mTvOut._SetOrientation(rotation);
+ }
+
+ private void enable() {
+ mTvOut._SetTvSystem(mSystem);
+ mTvOut._TvOutSetImageString("TV-out not supported while application running. Phone display only");
+
+ Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+ mTvOut._SetOrientation(display.getRotation());
+
+ mTvOut._EnableTvOut();
+ mTvOut._setTvoutCableConnected(1);
+
+ // Start tvouthack service used to bombard screen refresh messages
+ SystemProperties.set("ctl.start", "tvouthack");
+ }
+
+ private void disable() {
+ SystemProperties.set("ctl.stop", "tvouthack");
+
+ mTvOut._DisableTvOut();
+ mTvOut._setTvoutCableConnected(0);
+ }
+
+}