Chromium Code Reviews| Index: blimp/client/app/android/java/src/org/chromium/blimp/toolbar/Toolbar.java |
| diff --git a/blimp/client/app/android/java/src/org/chromium/blimp/toolbar/Toolbar.java b/blimp/client/app/android/java/src/org/chromium/blimp/toolbar/Toolbar.java |
| index a6c188e7b07cd2f2f347ee155b73d929e70ac590..439aba0d64519bee1ecf0449aaf50b81f3d356c9 100644 |
| --- a/blimp/client/app/android/java/src/org/chromium/blimp/toolbar/Toolbar.java |
| +++ b/blimp/client/app/android/java/src/org/chromium/blimp/toolbar/Toolbar.java |
| @@ -22,12 +22,16 @@ import android.widget.ProgressBar; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.blimp.BlimpRendererActivity; |
| import org.chromium.blimp.R; |
| import org.chromium.blimp.session.BlimpClientSession; |
| import org.chromium.blimp.session.EngineInfo; |
| import org.chromium.blimp.settings.AboutBlimpPreferences; |
| import org.chromium.blimp.settings.Preferences; |
| +import java.util.ArrayList; |
| +import java.util.List; |
| + |
| /** |
| * A {@link View} that visually represents the Blimp toolbar, which lets users issue navigation |
| * commands and displays relevant navigation UI. |
| @@ -38,10 +42,12 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver, View |
| private static final String TAG = "Toolbar"; |
| private static final int ID_OPEN_IN_CHROME = 0; |
| private static final int ID_VERSION_INFO = 1; |
| + private static final int ID_TOGGLE_DEBUG_INFO = 2; |
| private long mNativeToolbarPtr; |
| private Context mContext; |
| + private BlimpClientSession mBlimpClientSession; |
| private UrlBar mUrlBar; |
| private ImageButton mReloadButton; |
| private ImageButton mMenuButton; |
| @@ -49,7 +55,9 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver, View |
| private ProgressBar mProgressBar; |
| private EngineInfo mEngineInfo; |
| - |
| + private boolean mDebugInfoEnabled = false; |
|
Khushal
2016/05/18 00:23:00
A comment here which says that this denotes whethe
shaktisahu
2016/05/19 21:39:18
Done.
|
| + private List<String> mMenuTitles; |
| + private ArrayAdapter<String> mAdapter; |
|
Khushal
2016/05/18 00:23:00
Rename this mPopupMenuOptionsAdapter so its clear
shaktisahu
2016/05/19 21:39:18
Done.
|
| /** |
| * A URL to load when this object is initialized. This handles the case where there is a URL |
| * to load before native is ready to receive any URL. |
| @@ -77,6 +85,7 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver, View |
| mNativeToolbarPtr = nativeInit(blimpClientSession); |
| sendUrlTextInternal(mUrlToLoad); |
| + mBlimpClientSession = blimpClientSession; |
| } |
| /** |
| @@ -192,9 +201,7 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver, View |
| */ |
| private void initializeMenu(View anchorView) { |
| mPopupMenu = new ListPopupWindow(mContext); |
| - mPopupMenu.setAdapter(new ArrayAdapter<String>(mContext, R.layout.toolbar_popup_item, |
| - new String[] {mContext.getString(R.string.open_in_chrome), |
| - mContext.getString(R.string.version_info)})); |
| + intializeMenuAdapter(); |
| mPopupMenu.setAnchorView(anchorView); |
| mPopupMenu.setWidth(getResources().getDimensionPixelSize(R.dimen.toolbar_popup_item_width)); |
| mPopupMenu.setVerticalOffset(-anchorView.getHeight()); |
| @@ -206,12 +213,25 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver, View |
| openInChrome(); |
| } else if (position == ID_VERSION_INFO) { |
| showVersionInfo(); |
| + } else if (position == ID_TOGGLE_DEBUG_INFO) { |
| + toggleDebugInfo(); |
| } |
| mPopupMenu.dismiss(); |
| } |
| }); |
| } |
| + private void intializeMenuAdapter() { |
| + mMenuTitles = new ArrayList<>(); |
| + mMenuTitles.add(mContext.getString(R.string.open_in_chrome)); |
| + mMenuTitles.add(mContext.getString(R.string.version_info)); |
| + mMenuTitles.add(mContext.getString( |
| + mDebugInfoEnabled ? R.string.hide_debug_info : R.string.show_debug_info)); |
| + |
| + mAdapter = new ArrayAdapter<String>(mContext, R.layout.toolbar_popup_item, mMenuTitles); |
| + mPopupMenu.setAdapter(mAdapter); |
| + } |
| + |
| private void openInChrome() { |
| Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUrlBar.getText().toString())); |
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| @@ -234,6 +254,19 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver, View |
| mContext.startActivity(intent); |
| } |
| + private void toggleDebugInfo() { |
| + mDebugInfoEnabled = !mDebugInfoEnabled; |
| + mMenuTitles.set(ID_TOGGLE_DEBUG_INFO, |
| + mContext.getString( |
| + mDebugInfoEnabled ? R.string.hide_debug_info : R.string.show_debug_info)); |
| + mAdapter.notifyDataSetChanged(); |
| + |
| + BlimpRendererActivity activity = (BlimpRendererActivity) mContext; |
|
Khushal
2016/05/18 00:23:00
Just a note from our discussion earlier, please do
shaktisahu
2016/05/19 21:39:18
Done.
|
| + activity.showDebugView(mDebugInfoEnabled); |
| + |
| + mBlimpClientSession.enableDebugInfo(mDebugInfoEnabled); |
| + } |
| + |
| // BlimpClientSession.ConnectionObserver interface. |
| @Override |
| public void onAssignmentReceived( |
| @@ -255,6 +288,9 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver, View |
| mEngineInfo.setConnected(false); |
| } |
| + @Override |
| + public void updateDebugInfo(int received, int sent, int commit) {} |
| + |
| // Methods that are called by native via JNI. |
| @CalledByNative |
| private void onEngineSentUrl(String url) { |