| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chromecast.shell; | 5 package org.chromium.chromecast.shell; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.BroadcastReceiver; | 8 import android.content.BroadcastReceiver; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| 11 import android.content.IntentFilter; | 11 import android.content.IntentFilter; |
| 12 import android.media.AudioManager; | 12 import android.media.AudioManager; |
| 13 import android.net.Uri; | 13 import android.net.Uri; |
| 14 import android.os.Build; | 14 import android.os.Build; |
| 15 import android.os.Bundle; | 15 import android.os.Bundle; |
| 16 import android.support.v4.content.LocalBroadcastManager; | 16 import android.support.v4.content.LocalBroadcastManager; |
| 17 import android.view.KeyEvent; | 17 import android.view.KeyEvent; |
| 18 import android.view.MotionEvent; | 18 import android.view.MotionEvent; |
| 19 import android.view.WindowManager; | 19 import android.view.WindowManager; |
| 20 import android.widget.Toast; | 20 import android.widget.Toast; |
| 21 | 21 |
| 22 import org.chromium.base.CommandLine; | |
| 23 import org.chromium.base.Log; | 22 import org.chromium.base.Log; |
| 24 import org.chromium.content.browser.ActivityContentVideoViewEmbedder; | 23 import org.chromium.content.browser.ActivityContentVideoViewEmbedder; |
| 25 import org.chromium.content.browser.ContentVideoViewEmbedder; | 24 import org.chromium.content.browser.ContentVideoViewEmbedder; |
| 26 import org.chromium.content.browser.ContentViewClient; | 25 import org.chromium.content.browser.ContentViewClient; |
| 27 import org.chromium.content.browser.ContentViewCore; | 26 import org.chromium.content.browser.ContentViewCore; |
| 28 import org.chromium.content.common.ContentSwitches; | |
| 29 import org.chromium.ui.base.WindowAndroid; | 27 import org.chromium.ui.base.WindowAndroid; |
| 30 | 28 |
| 31 /** | 29 /** |
| 32 * Activity for managing the Cast shell. | 30 * Activity for managing the Cast shell. |
| 33 */ | 31 */ |
| 34 public class CastShellActivity extends Activity { | 32 public class CastShellActivity extends Activity { |
| 35 private static final String TAG = "cr_CastShellActivity"; | 33 private static final String TAG = "cr_CastShellActivity"; |
| 36 private static final boolean DEBUG = false; | 34 private static final boolean DEBUG = false; |
| 37 | 35 |
| 38 private static final String ACTIVE_SHELL_URL_KEY = "activeUrl"; | 36 private static final String ACTIVE_SHELL_URL_KEY = "activeUrl"; |
| 39 private static final int DEFAULT_HEIGHT_PIXELS = 720; | |
| 40 public static final String ACTION_EXTRA_RESOLUTION_HEIGHT = | |
| 41 "org.chromium.chromecast.shell.intent.extra.RESOLUTION_HEIGHT"; | |
| 42 | 37 |
| 43 private CastWindowManager mCastWindowManager; | 38 private CastWindowManager mCastWindowManager; |
| 44 private AudioManager mAudioManager; | 39 private AudioManager mAudioManager; |
| 45 private BroadcastReceiver mBroadcastReceiver; | 40 private BroadcastReceiver mBroadcastReceiver; |
| 46 private boolean mReceivedUserLeave = false; | 41 private boolean mReceivedUserLeave = false; |
| 47 | 42 |
| 48 // Native window instance. | 43 // Native window instance. |
| 49 // TODO(byungchul, gunsch): CastShellActivity, CastWindowAndroid, and native
CastWindowAndroid | 44 // TODO(byungchul, gunsch): CastShellActivity, CastWindowAndroid, and native
CastWindowAndroid |
| 50 // have a one-to-one relationship. Consider instantiating CastWindow here an
d CastWindow having | 45 // have a one-to-one relationship. Consider instantiating CastWindow here an
d CastWindow having |
| 51 // this native shell instance. | 46 // this native shell instance. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 public void onCreated() { | 100 public void onCreated() { |
| 106 } | 101 } |
| 107 | 102 |
| 108 @Override | 103 @Override |
| 109 public void onClosed() { | 104 public void onClosed() { |
| 110 mNativeCastWindow = 0; | 105 mNativeCastWindow = 0; |
| 111 mCastWindowManager.setDelegate(null); | 106 mCastWindowManager.setDelegate(null); |
| 112 finish(); | 107 finish(); |
| 113 } | 108 } |
| 114 }); | 109 }); |
| 115 setResolution(); | |
| 116 mCastWindowManager.setWindow(new WindowAndroid(this)); | 110 mCastWindowManager.setWindow(new WindowAndroid(this)); |
| 117 | 111 |
| 118 registerBroadcastReceiver(); | 112 registerBroadcastReceiver(); |
| 119 | 113 |
| 120 String url = getIntent().getDataString(); | 114 String url = getIntent().getDataString(); |
| 121 Log.d(TAG, "onCreate startupUrl: %s", url); | 115 Log.d(TAG, "onCreate startupUrl: %s", url); |
| 122 mNativeCastWindow = mCastWindowManager.launchCastWindow(url); | 116 mNativeCastWindow = mCastWindowManager.launchCastWindow(url); |
| 123 | 117 |
| 124 getActiveContentViewCore().setContentViewClient(new ContentViewClient()
{ | 118 getActiveContentViewCore().setContentViewClient(new ContentViewClient()
{ |
| 125 @Override | 119 @Override |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 devtoolsBroadcastIntentFilter.addAction(CastWindowAndroid.ACTION_DISABLE
_DEV_TOOLS); | 257 devtoolsBroadcastIntentFilter.addAction(CastWindowAndroid.ACTION_DISABLE
_DEV_TOOLS); |
| 264 LocalBroadcastManager.getInstance(this) | 258 LocalBroadcastManager.getInstance(this) |
| 265 .registerReceiver(mBroadcastReceiver, devtoolsBroadcastIntentFil
ter); | 259 .registerReceiver(mBroadcastReceiver, devtoolsBroadcastIntentFil
ter); |
| 266 } | 260 } |
| 267 | 261 |
| 268 private void unregisterBroadcastReceiver() { | 262 private void unregisterBroadcastReceiver() { |
| 269 LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstan
ce(this); | 263 LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstan
ce(this); |
| 270 broadcastManager.unregisterReceiver(mBroadcastReceiver); | 264 broadcastManager.unregisterReceiver(mBroadcastReceiver); |
| 271 } | 265 } |
| 272 | 266 |
| 273 private void setResolution() { | |
| 274 CommandLine commandLine = CommandLine.getInstance(); | |
| 275 int defaultHeight = DEFAULT_HEIGHT_PIXELS; | |
| 276 if (commandLine.hasSwitch(CastSwitches.DEFAULT_RESOLUTION_HEIGHT)) { | |
| 277 String commandLineHeightString = | |
| 278 commandLine.getSwitchValue(CastSwitches.DEFAULT_RESOLUTION_H
EIGHT); | |
| 279 try { | |
| 280 defaultHeight = Integer.parseInt(commandLineHeightString); | |
| 281 } catch (NumberFormatException e) { | |
| 282 Log.w(TAG, "Ignored invalid height: %d", commandLineHeightString
); | |
| 283 } | |
| 284 } | |
| 285 int requestedHeight = | |
| 286 getIntent().getIntExtra(ACTION_EXTRA_RESOLUTION_HEIGHT, defaultH
eight); | |
| 287 int displayHeight = getResources().getDisplayMetrics().heightPixels; | |
| 288 // Clamp within [defaultHeight, displayHeight] | |
| 289 int desiredHeight = Math.min(displayHeight, Math.max(defaultHeight, requ
estedHeight)); | |
| 290 double deviceScaleFactor = ((double) displayHeight) / desiredHeight; | |
| 291 Log.d(TAG, "Using scale factor %f to set height %d", deviceScaleFactor,
desiredHeight); | |
| 292 commandLine.appendSwitchWithValue( | |
| 293 ContentSwitches.FORCE_DEVICE_SCALE_FACTOR, String.valueOf(device
ScaleFactor)); | |
| 294 } | |
| 295 | |
| 296 private void exitIfUrlMissing() { | 267 private void exitIfUrlMissing() { |
| 297 Intent intent = getIntent(); | 268 Intent intent = getIntent(); |
| 298 if (intent != null && intent.getData() != null && !intent.getData().equa
ls(Uri.EMPTY)) { | 269 if (intent != null && intent.getData() != null && !intent.getData().equa
ls(Uri.EMPTY)) { |
| 299 return; | 270 return; |
| 300 } | 271 } |
| 301 // Log an exception so that the exit cause is obvious when reading the l
ogs. | 272 // Log an exception so that the exit cause is obvious when reading the l
ogs. |
| 302 Log.e(TAG, "Activity will not start", | 273 Log.e(TAG, "Activity will not start", |
| 303 new IllegalArgumentException("Intent did not contain a valid url
")); | 274 new IllegalArgumentException("Intent did not contain a valid url
")); |
| 304 System.exit(-1); | 275 System.exit(-1); |
| 305 } | 276 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 @Override | 324 @Override |
| 354 public boolean dispatchTouchEvent(MotionEvent ev) { | 325 public boolean dispatchTouchEvent(MotionEvent ev) { |
| 355 return false; | 326 return false; |
| 356 } | 327 } |
| 357 | 328 |
| 358 @Override | 329 @Override |
| 359 public boolean dispatchTrackballEvent(MotionEvent ev) { | 330 public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 360 return false; | 331 return false; |
| 361 } | 332 } |
| 362 } | 333 } |
| OLD | NEW |