Chromium Code Reviews| Index: blimp/client/app/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| diff --git a/blimp/client/app/android/java/src/org/chromium/blimp/BlimpRendererActivity.java b/blimp/client/app/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| index cd830b17b1aba6d5e200fea9d0bc964f633cfaa1..394bad1981caf776271f6b298a30de4e53320a79 100644 |
| --- a/blimp/client/app/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| +++ b/blimp/client/app/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| @@ -7,7 +7,10 @@ package org.chromium.blimp; |
| import android.app.Activity; |
| import android.content.Intent; |
| import android.os.Bundle; |
| +import android.os.Handler; |
| import android.text.TextUtils; |
| +import android.view.View; |
| +import android.widget.TextView; |
| import org.chromium.base.Log; |
| import org.chromium.base.annotations.SuppressFBWarnings; |
| @@ -21,6 +24,7 @@ import org.chromium.blimp.session.BlimpClientSession; |
| import org.chromium.blimp.session.EngineInfo; |
| import org.chromium.blimp.session.TabControlFeature; |
| import org.chromium.blimp.toolbar.Toolbar; |
| +import org.chromium.blimp.toolbar.ToolbarMenu; |
| import org.chromium.ui.widget.Toast; |
| /** |
| @@ -29,10 +33,14 @@ import org.chromium.ui.widget.Toast; |
| */ |
| public class BlimpRendererActivity |
| extends Activity implements BlimpLibraryLoader.Callback, TokenSource.Callback, |
| - BlimpClientSession.ConnectionObserver { |
| + BlimpClientSession.ConnectionObserver, |
| + ToolbarMenu.ToolbarMenuDelegate, Toolbar.ToolbarDelegate { |
| private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; |
| private static final String TAG = "BlimpRendererActivity"; |
| + // Refresh interval for the debug view in milliseconds. |
| + private static final int DEBUG_VIEW_REFRESH_INTERVAL = 1000; |
| + |
| /** Provides user authentication tokens that can be used to query for engine assignments. This |
| * can potentially query GoogleAuthUtil for an OAuth2 authentication token with userinfo.email |
| * privileges for a chosen Android account. */ |
| @@ -44,8 +52,19 @@ public class BlimpRendererActivity |
| private TabControlFeature mTabControlFeature; |
| private WebInputBox mWebInputBox; |
| + private Handler mHandler = new Handler(); |
| + |
| private boolean mFirstUrlLoadDone = false; |
| + // Flag to record the base value of the metrics when the debug view is turned on. |
| + private boolean mStatsBaseRecorded = false; |
| + private int mSentBase; |
| + private int mReceivedBase; |
| + private int mCommitsBase; |
| + private int mSent; |
| + private int mReceived; |
| + private int mCommits; |
| + |
| @Override |
| @SuppressFBWarnings("DM_EXIT") // FindBugs doesn't like System.exit(). |
| protected void onCreate(Bundle savedInstanceState) { |
| @@ -83,9 +102,6 @@ public class BlimpRendererActivity |
| } |
| if (mToolbar != null) { |
| - if (mBlimpClientSession != null) { |
| - mBlimpClientSession.removeObserver(mToolbar); |
| - } |
| mToolbar.destroy(); |
| mToolbar = null; |
| } |
| @@ -153,8 +169,7 @@ public class BlimpRendererActivity |
| mBlimpView.initializeRenderer(mBlimpClientSession); |
| mToolbar = (Toolbar) findViewById(R.id.toolbar); |
| - mToolbar.initialize(mBlimpClientSession); |
| - mBlimpClientSession.addObserver(mToolbar); |
| + mToolbar.initialize(mBlimpClientSession, this); |
| mWebInputBox = (WebInputBox) findViewById(R.id.editText); |
| mWebInputBox.initialize(mBlimpClientSession); |
| @@ -164,6 +179,28 @@ public class BlimpRendererActivity |
| handleUrlFromIntent(getIntent()); |
| } |
| + // ToolbarMenu.ToolbarMenuDelegate implementation. |
| + @Override |
| + public void showDebugView(boolean show) { |
| + View debugView = findViewById(R.id.debug_stats); |
| + debugView.setVisibility(show ? View.VISIBLE : View.INVISIBLE); |
| + if (show) { |
| + Runnable debugStatsRunnable = new Runnable() { |
| + @Override |
| + public void run() { |
| + if (mToolbar.getToolbarMenu().isDebugInfoEnabled()) { |
| + int[] metrics = mBlimpClientSession.getDebugStats(); |
| + updateDebugStats(metrics); |
| + mHandler.postDelayed(this, DEBUG_VIEW_REFRESH_INTERVAL); |
| + } |
| + } |
| + }; |
| + debugStatsRunnable.run(); |
| + } else { |
| + mStatsBaseRecorded = false; |
| + } |
| + } |
| + |
| @Override |
| protected void onNewIntent(Intent intent) { |
| super.onNewIntent(intent); |
| @@ -234,6 +271,38 @@ public class BlimpRendererActivity |
| } |
| @Override |
| + public void updateDebugStatsUI(int received, int sent, int commits) { |
| + TextView tv = (TextView) findViewById(R.id.bytes_received_client); |
| + tv.setText(String.valueOf(received / 1000)); |
|
Kevin M
2016/05/24 01:02:00
If this is in kilobytes, then this should be 1024.
Kevin M
2016/05/24 01:02:00
Should we be doing a floating point divide, so tha
shaktisahu
2016/05/24 21:02:44
Done.
shaktisahu
2016/05/24 21:02:44
Done.
|
| + tv = (TextView) findViewById(R.id.bytes_sent_client); |
| + tv.setText(String.valueOf(sent / 1000)); |
| + tv = (TextView) findViewById(R.id.commit_count); |
| + tv.setText(String.valueOf(commits)); |
| + } |
| + |
| + private void updateDebugStats(int[] metrics) { |
| + assert metrics.length == 3; |
| + mReceived = metrics[0]; |
| + mSent = metrics[1]; |
| + mCommits = metrics[2]; |
| + if (!mStatsBaseRecorded) { |
| + mReceivedBase = mReceived; |
| + mSentBase = mSent; |
| + mCommitsBase = mCommits; |
| + mStatsBaseRecorded = true; |
| + } |
| + updateDebugStatsUI(mReceived - mReceivedBase, mSent - mSentBase, mCommits - mCommitsBase); |
| + } |
| + |
| + // Toolbar.ToolbarDelegate interface. |
| + @Override |
| + public void resetDebugStats() { |
| + mReceivedBase = mReceived; |
| + mSentBase = mSent; |
| + mCommitsBase = mCommits; |
| + } |
| + |
| + @Override |
| public void onDisconnected(String reason) { |
| Toast.makeText(this, |
| String.format(getResources().getString(R.string.network_disconnected), reason), |