Skip to content

Commit

Permalink
tv support
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Sep 15, 2019
1 parent 60b4dbf commit ea3ea77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SoundEffectConstants;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -204,6 +205,8 @@ void setTheme() {
}

void setOrientation() {
if (isTV())
return;
String o = options.getString(Options.PREF_ORIENTATION, "automatic");
if (o.equals("landscape"))
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Expand Down Expand Up @@ -372,10 +375,12 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onKeyDown(keyCode, event);
}
if (isFirstButton(keyCode)) {
chrono.playSoundEffect(SoundEffectConstants.CLICK);
pressFirstButton();
return true;
}
else if (isSecondButton(keyCode)) {
chrono.playSoundEffect(SoundEffectConstants.CLICK);
pressSecondButton();
return true;
}
Expand Down Expand Up @@ -433,7 +438,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

public void lockOrientation() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
if (!isTV() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
switch(((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation()) {
case Surface.ROTATION_0:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Expand Down Expand Up @@ -587,6 +592,15 @@ public static void vibrate(Activity context, long time) {
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(time);
}

public boolean isTV() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
return getPackageManager().hasSystemFeature("android.hardware.type.television");
}
else {
return false;
}
}
}

class MyStateDrawable extends StateListDrawable {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_stop_watch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical"
android:soundEffectsEnabled="true"
tools:context=".StopWatch">

<omegacentauri.mobi.simplestopwatch.BigTextView
Expand Down

0 comments on commit ea3ea77

Please sign in to comment.