| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.chromoting; | 5 package org.chromium.chromoting; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.app.ProgressDialog; | 8 import android.app.ProgressDialog; |
| 9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 import android.view.MenuItem; | 26 import android.view.MenuItem; |
| 27 import android.view.View; | 27 import android.view.View; |
| 28 import android.widget.AdapterView; | 28 import android.widget.AdapterView; |
| 29 import android.widget.ArrayAdapter; | 29 import android.widget.ArrayAdapter; |
| 30 import android.widget.LinearLayout; | 30 import android.widget.LinearLayout; |
| 31 import android.widget.ListView; | 31 import android.widget.ListView; |
| 32 import android.widget.Toast; | 32 import android.widget.Toast; |
| 33 | 33 |
| 34 import org.chromium.base.ApiCompatibilityUtils; | 34 import org.chromium.base.ApiCompatibilityUtils; |
| 35 import org.chromium.base.Log; | 35 import org.chromium.base.Log; |
| 36 import org.chromium.chromoting.NavigationMenuAdapter.NavigationMenuItem; |
| 36 import org.chromium.chromoting.accountswitcher.AccountSwitcher; | 37 import org.chromium.chromoting.accountswitcher.AccountSwitcher; |
| 37 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; | 38 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; |
| 38 import org.chromium.chromoting.base.OAuthTokenFetcher; | 39 import org.chromium.chromoting.base.OAuthTokenFetcher; |
| 40 import org.chromium.chromoting.help.CreditsActivity; |
| 39 import org.chromium.chromoting.help.HelpContext; | 41 import org.chromium.chromoting.help.HelpContext; |
| 40 import org.chromium.chromoting.help.HelpSingleton; | 42 import org.chromium.chromoting.help.HelpSingleton; |
| 41 import org.chromium.chromoting.jni.Client; | 43 import org.chromium.chromoting.jni.Client; |
| 42 import org.chromium.chromoting.jni.ConnectionListener; | 44 import org.chromium.chromoting.jni.ConnectionListener; |
| 43 import org.chromium.chromoting.jni.JniInterface; | 45 import org.chromium.chromoting.jni.JniInterface; |
| 44 | 46 |
| 45 import java.util.ArrayList; | 47 import java.util.ArrayList; |
| 46 import java.util.Arrays; | 48 import java.util.Arrays; |
| 47 | 49 |
| 48 /** | 50 /** |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 * Shows the appropriate view for the host list and hides the loading indica
tor. Shows either | 165 * Shows the appropriate view for the host list and hides the loading indica
tor. Shows either |
| 164 * the host list chooser or the host list empty view, depending on whether m
Hosts contains any | 166 * the host list chooser or the host list empty view, depending on whether m
Hosts contains any |
| 165 * hosts. | 167 * hosts. |
| 166 */ | 168 */ |
| 167 private void updateHostListView() { | 169 private void updateHostListView() { |
| 168 mHostListView.setVisibility(mHosts.length == 0 ? View.GONE : View.VISIBL
E); | 170 mHostListView.setVisibility(mHosts.length == 0 ? View.GONE : View.VISIBL
E); |
| 169 mEmptyView.setVisibility(mHosts.length == 0 ? View.VISIBLE : View.GONE); | 171 mEmptyView.setVisibility(mHosts.length == 0 ? View.VISIBLE : View.GONE); |
| 170 mProgressView.setVisibility(View.GONE); | 172 mProgressView.setVisibility(View.GONE); |
| 171 } | 173 } |
| 172 | 174 |
| 175 private ListView createNavigationMenu() { |
| 176 ListView navigationMenu = (ListView) getLayoutInflater() |
| 177 .inflate(R.layout.navigation_list, null); |
| 178 |
| 179 NavigationMenuItem helpItem = new NavigationMenuItem(R.menu.help_list_it
em, |
| 180 new Runnable() { |
| 181 @Override |
| 182 public void run() { |
| 183 HelpSingleton.getInstance().launchHelp(Chromoting.this, |
| 184 HelpContext.HOST_LIST); |
| 185 } |
| 186 }); |
| 187 |
| 188 NavigationMenuItem creditsItem = new NavigationMenuItem(R.menu.credits_l
ist_item, |
| 189 new Runnable() { |
| 190 @Override |
| 191 public void run() { |
| 192 startActivity(new Intent(Chromoting.this, CreditsActivit
y.class)); |
| 193 } |
| 194 }); |
| 195 |
| 196 NavigationMenuItem[] navigationMenuItems = { helpItem, creditsItem }; |
| 197 NavigationMenuAdapter adapter = new NavigationMenuAdapter(this, navigati
onMenuItems); |
| 198 navigationMenu.setAdapter(adapter); |
| 199 navigationMenu.setOnItemClickListener(adapter); |
| 200 return navigationMenu; |
| 201 } |
| 202 |
| 173 /** | 203 /** |
| 174 * Called when the activity is first created. Loads the native library and r
equests an | 204 * Called when the activity is first created. Loads the native library and r
equests an |
| 175 * authentication token from the system. | 205 * authentication token from the system. |
| 176 */ | 206 */ |
| 177 @Override | 207 @Override |
| 178 public void onCreate(Bundle savedInstanceState) { | 208 public void onCreate(Bundle savedInstanceState) { |
| 179 super.onCreate(savedInstanceState); | 209 super.onCreate(savedInstanceState); |
| 180 setContentView(R.layout.main); | 210 setContentView(R.layout.main); |
| 181 | 211 |
| 182 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | 212 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 263 } |
| 234 }); | 264 }); |
| 235 | 265 |
| 236 // Set the three-line icon instead of the default which is a tinted arro
w icon. | 266 // Set the three-line icon instead of the default which is a tinted arro
w icon. |
| 237 getSupportActionBar().setDisplayHomeAsUpEnabled(true); | 267 getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 238 Drawable menuIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.
drawable.ic_menu); | 268 Drawable menuIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.
drawable.ic_menu); |
| 239 DrawableCompat.setTint(menuIcon.mutate(), | 269 DrawableCompat.setTint(menuIcon.mutate(), |
| 240 ChromotingUtil.getColorAttribute(this, R.attr.colorControlNormal
)); | 270 ChromotingUtil.getColorAttribute(this, R.attr.colorControlNormal
)); |
| 241 getSupportActionBar().setHomeAsUpIndicator(menuIcon); | 271 getSupportActionBar().setHomeAsUpIndicator(menuIcon); |
| 242 | 272 |
| 243 ListView navigationMenu = new ListView(this); | |
| 244 navigationMenu.setChoiceMode(ListView.CHOICE_MODE_SINGLE); | |
| 245 navigationMenu.setLayoutParams(new LinearLayout.LayoutParams( | |
| 246 LinearLayout.LayoutParams.MATCH_PARENT, | |
| 247 LinearLayout.LayoutParams.MATCH_PARENT)); | |
| 248 | |
| 249 String[] navigationMenuItems = new String[] { | |
| 250 getString(R.string.actionbar_help) | |
| 251 }; | |
| 252 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.n
avigation_list_item, | |
| 253 navigationMenuItems); | |
| 254 navigationMenu.setAdapter(adapter); | |
| 255 navigationMenu.setOnItemClickListener( | |
| 256 new AdapterView.OnItemClickListener() { | |
| 257 @Override | |
| 258 public void onItemClick(AdapterView<?> parent, View view, in
t position, | |
| 259 long id) { | |
| 260 HelpSingleton.getInstance().launchHelp(Chromoting.this, | |
| 261 HelpContext.HOST_LIST); | |
| 262 } | |
| 263 }); | |
| 264 | |
| 265 mAccountSwitcher = AccountSwitcherFactory.getInstance().createAccountSwi
tcher(this, this); | 273 mAccountSwitcher = AccountSwitcherFactory.getInstance().createAccountSwi
tcher(this, this); |
| 266 mAccountSwitcher.setNavigation(navigationMenu); | 274 mAccountSwitcher.setNavigation(createNavigationMenu()); |
| 267 LinearLayout navigationDrawer = (LinearLayout) findViewById(R.id.navigat
ion_drawer); | 275 LinearLayout navigationDrawer = (LinearLayout) findViewById(R.id.navigat
ion_drawer); |
| 268 mAccountSwitcher.setDrawer(navigationDrawer); | 276 mAccountSwitcher.setDrawer(navigationDrawer); |
| 269 View switcherView = mAccountSwitcher.getView(); | 277 View switcherView = mAccountSwitcher.getView(); |
| 270 switcherView.setLayoutParams(new LinearLayout.LayoutParams( | 278 switcherView.setLayoutParams(new LinearLayout.LayoutParams( |
| 271 LinearLayout.LayoutParams.MATCH_PARENT, | 279 LinearLayout.LayoutParams.MATCH_PARENT, |
| 272 LinearLayout.LayoutParams.WRAP_CONTENT)); | 280 LinearLayout.LayoutParams.WRAP_CONTENT)); |
| 273 navigationDrawer.addView(switcherView, 0); | 281 navigationDrawer.addView(switcherView, 0); |
| 274 | 282 |
| 275 mHostConnectingConsumer = new OAuthTokenConsumer(this, TOKEN_SCOPE); | 283 mHostConnectingConsumer = new OAuthTokenConsumer(this, TOKEN_SCOPE); |
| 276 mHostListRetrievingConsumer = new OAuthTokenConsumer(this, TOKEN_SCOPE); | 284 mHostListRetrievingConsumer = new OAuthTokenConsumer(this, TOKEN_SCOPE); |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 // Unreachable, but required by Google Java style and findbugs. | 708 // Unreachable, but required by Google Java style and findbugs. |
| 701 assert false : "Unreached"; | 709 assert false : "Unreached"; |
| 702 } | 710 } |
| 703 | 711 |
| 704 if (dismissProgress && mProgressIndicator != null) { | 712 if (dismissProgress && mProgressIndicator != null) { |
| 705 mProgressIndicator.dismiss(); | 713 mProgressIndicator.dismiss(); |
| 706 mProgressIndicator = null; | 714 mProgressIndicator = null; |
| 707 } | 715 } |
| 708 } | 716 } |
| 709 } | 717 } |
| OLD | NEW |