diff options
author | Jae Seo <jaeseo@google.com> | 2014-05-20 17:48:33 -0700 |
---|---|---|
committer | Jae Seo <jaeseo@google.com> | 2014-05-20 17:48:33 -0700 |
commit | ac7dbe9c324443641fcfa840a06e47c27bbdedfd (patch) | |
tree | 4302592cea0a5192308f47b8fedfbcd0bc8fbf96 /src/com/android/tv | |
parent | 9419bd5aa79ca40126b949a90c3a4c999361f72d (diff) | |
download | TV-ac7dbe9c324443641fcfa840a06e47c27bbdedfd.tar.gz |
Add a global key receiver to handle KEYCODE_TV
Bug: 15081439
Change-Id: Ie56cf1a526f2185cc35c7371b68d697839e31664
Diffstat (limited to 'src/com/android/tv')
-rw-r--r-- | src/com/android/tv/receiver/GlobalKeyReceiver.java | 49 | ||||
-rw-r--r-- | src/com/android/tv/receiver/PackageIntentsReceiver.java (renamed from src/com/android/tv/PackageIntentsReceiver.java) | 2 |
2 files changed, 50 insertions, 1 deletions
diff --git a/src/com/android/tv/receiver/GlobalKeyReceiver.java b/src/com/android/tv/receiver/GlobalKeyReceiver.java new file mode 100644 index 00000000..ca925baf --- /dev/null +++ b/src/com/android/tv/receiver/GlobalKeyReceiver.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.tv.receiver; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import android.view.KeyEvent; + +import com.android.tv.TvActivity; + +/** + * Handles global keys. + */ +public class GlobalKeyReceiver extends BroadcastReceiver { + private static final boolean DEBUG = true; + private static final String TAG = "GlobalKeyReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_GLOBAL_BUTTON.equals(intent.getAction())) { + KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); + if (DEBUG) + Log.d(TAG, "onReceive: " + event); + int keyCode = event.getKeyCode(); + int action = event.getAction(); + if (keyCode == KeyEvent.KEYCODE_TV && action == KeyEvent.ACTION_DOWN) { + Intent newIntent = new Intent(context, TvActivity.class); + newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(newIntent); + } + } + } +}
\ No newline at end of file diff --git a/src/com/android/tv/PackageIntentsReceiver.java b/src/com/android/tv/receiver/PackageIntentsReceiver.java index eeb2dd7e..43f54a47 100644 --- a/src/com/android/tv/PackageIntentsReceiver.java +++ b/src/com/android/tv/receiver/PackageIntentsReceiver.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.tv; +package com.android.tv.receiver; import android.content.BroadcastReceiver; import android.content.Context; |