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.AlertDialog; | 8 import android.app.AlertDialog; |
9 import android.app.ProgressDialog; | 9 import android.app.ProgressDialog; |
10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.SharedPreferences; | 12 import android.content.SharedPreferences; |
13 import android.content.res.Configuration; | 13 import android.content.res.Configuration; |
| 14 import android.graphics.drawable.Drawable; |
14 import android.os.Bundle; | 15 import android.os.Bundle; |
15 import android.provider.Settings; | 16 import android.provider.Settings; |
| 17 import android.support.v4.graphics.drawable.DrawableCompat; |
16 import android.support.v4.widget.DrawerLayout; | 18 import android.support.v4.widget.DrawerLayout; |
17 import android.support.v7.app.ActionBarDrawerToggle; | 19 import android.support.v7.app.ActionBarDrawerToggle; |
18 import android.support.v7.app.AppCompatActivity; | 20 import android.support.v7.app.AppCompatActivity; |
19 import android.support.v7.widget.Toolbar; | 21 import android.support.v7.widget.Toolbar; |
| 22 import android.view.Gravity; |
20 import android.view.Menu; | 23 import android.view.Menu; |
21 import android.view.MenuItem; | 24 import android.view.MenuItem; |
22 import android.view.View; | 25 import android.view.View; |
23 import android.widget.AdapterView; | 26 import android.widget.AdapterView; |
24 import android.widget.ArrayAdapter; | 27 import android.widget.ArrayAdapter; |
25 import android.widget.LinearLayout; | 28 import android.widget.LinearLayout; |
26 import android.widget.ListView; | 29 import android.widget.ListView; |
27 import android.widget.Toast; | 30 import android.widget.Toast; |
28 | 31 |
| 32 import org.chromium.base.ApiCompatibilityUtils; |
29 import org.chromium.base.Log; | 33 import org.chromium.base.Log; |
30 import org.chromium.chromoting.accountswitcher.AccountSwitcher; | 34 import org.chromium.chromoting.accountswitcher.AccountSwitcher; |
31 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; | 35 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; |
32 import org.chromium.chromoting.help.HelpContext; | 36 import org.chromium.chromoting.help.HelpContext; |
33 import org.chromium.chromoting.help.HelpSingleton; | 37 import org.chromium.chromoting.help.HelpSingleton; |
34 import org.chromium.chromoting.jni.JniInterface; | 38 import org.chromium.chromoting.jni.JniInterface; |
35 | 39 |
36 import java.util.ArrayList; | 40 import java.util.ArrayList; |
37 import java.util.Arrays; | 41 import java.util.Arrays; |
38 | 42 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 long id) { | 182 long id) { |
179 onHostClicked(position); | 183 onHostClicked(position); |
180 } | 184 } |
181 }); | 185 }); |
182 | 186 |
183 mProgressView = findViewById(R.id.hostList_progress); | 187 mProgressView = findViewById(R.id.hostList_progress); |
184 | 188 |
185 findViewById(R.id.host_setup_link_android).setOnClickListener(this); | 189 findViewById(R.id.host_setup_link_android).setOnClickListener(this); |
186 | 190 |
187 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); | 191 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); |
188 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, | 192 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, |
189 R.string.open_navigation_drawer, R.string.close_navigation_drawe
r); | 193 R.string.open_navigation_drawer, R.string.close_navigation_drawe
r); |
190 mDrawerLayout.setDrawerListener(mDrawerToggle); | 194 mDrawerLayout.setDrawerListener(mDrawerToggle); |
191 | 195 |
| 196 // Disable the hamburger icon animation. This is more complex than it ou
ght to be. |
| 197 // The animation can be customized by tweaking some style parameters - s
ee |
| 198 // http://developer.android.com/reference/android/support/v7/appcompat/R
.styleable.html#DrawerArrowToggle . |
| 199 // But these can't disable the animation completely. |
| 200 // The icon can only be changed by disabling the drawer indicator, which
has side-effects |
| 201 // that must be worked around. It disables the built-in click listener,
so this has to be |
| 202 // implemented and added. This also requires that the toolbar be passed
to the |
| 203 // ActionBarDrawerToggle ctor above (otherwise the listener is ignored a
nd warnings are |
| 204 // logged). |
| 205 // Also, the animation itself is a private implementation detail - it is
not possible to |
| 206 // simply access the first frame of the animation. And the hamburger men
u icon doesn't |
| 207 // exist as a builtin Android resource, so it has to be provided as an a
pplication |
| 208 // resource instead (R.drawable.ic_menu). And, on Lollipop devices and a
bove, it should be |
| 209 // tinted to match the colorControlNormal theme attribute. |
| 210 mDrawerToggle.setDrawerIndicatorEnabled(false); |
| 211 mDrawerToggle.setToolbarNavigationClickListener( |
| 212 new View.OnClickListener() { |
| 213 @Override |
| 214 public void onClick(View view) { |
| 215 if (mDrawerLayout.isDrawerOpen(Gravity.START)) { |
| 216 mDrawerLayout.closeDrawer(Gravity.START); |
| 217 } else { |
| 218 mDrawerLayout.openDrawer(Gravity.START); |
| 219 } |
| 220 } |
| 221 }); |
| 222 |
| 223 // Set the three-line icon instead of the default which is a tinted arro
w icon. |
| 224 getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 225 Drawable menuIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.
drawable.ic_menu); |
| 226 DrawableCompat.setTint(menuIcon.mutate(), |
| 227 ChromotingUtil.getColorAttribute(this, R.attr.colorControlNormal
)); |
| 228 getSupportActionBar().setHomeAsUpIndicator(menuIcon); |
| 229 |
192 ListView navigationMenu = new ListView(this); | 230 ListView navigationMenu = new ListView(this); |
193 navigationMenu.setChoiceMode(ListView.CHOICE_MODE_SINGLE); | 231 navigationMenu.setChoiceMode(ListView.CHOICE_MODE_SINGLE); |
194 navigationMenu.setLayoutParams(new LinearLayout.LayoutParams( | 232 navigationMenu.setLayoutParams(new LinearLayout.LayoutParams( |
195 LinearLayout.LayoutParams.MATCH_PARENT, | 233 LinearLayout.LayoutParams.MATCH_PARENT, |
196 LinearLayout.LayoutParams.MATCH_PARENT)); | 234 LinearLayout.LayoutParams.MATCH_PARENT)); |
197 | 235 |
198 String[] navigationMenuItems = new String[] { | 236 String[] navigationMenuItems = new String[] { |
199 getString(R.string.actionbar_help) | 237 getString(R.string.actionbar_help) |
200 }; | 238 }; |
201 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.n
avigation_list_item, | 239 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.n
avigation_list_item, |
202 navigationMenuItems); | 240 navigationMenuItems); |
203 navigationMenu.setAdapter(adapter); | 241 navigationMenu.setAdapter(adapter); |
204 navigationMenu.setOnItemClickListener( | 242 navigationMenu.setOnItemClickListener( |
205 new AdapterView.OnItemClickListener() { | 243 new AdapterView.OnItemClickListener() { |
206 @Override | 244 @Override |
207 public void onItemClick(AdapterView<?> parent, View view, in
t position, | 245 public void onItemClick(AdapterView<?> parent, View view, in
t position, |
208 long id) { | 246 long id) { |
209 HelpSingleton.getInstance().launchHelp(Chromoting.this, | 247 HelpSingleton.getInstance().launchHelp(Chromoting.this, |
210 HelpContext.HOST_LIST); | 248 HelpContext.HOST_LIST); |
211 } | 249 } |
212 }); | 250 }); |
213 | 251 |
214 // Make the navigation drawer icon visible in the ActionBar. | |
215 getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
216 | |
217 mAccountSwitcher = AccountSwitcherFactory.getInstance().createAccountSwi
tcher(this, this); | 252 mAccountSwitcher = AccountSwitcherFactory.getInstance().createAccountSwi
tcher(this, this); |
218 mAccountSwitcher.setNavigation(navigationMenu); | 253 mAccountSwitcher.setNavigation(navigationMenu); |
219 LinearLayout navigationDrawer = (LinearLayout) findViewById(R.id.navigat
ion_drawer); | 254 LinearLayout navigationDrawer = (LinearLayout) findViewById(R.id.navigat
ion_drawer); |
220 mAccountSwitcher.setDrawer(navigationDrawer); | 255 mAccountSwitcher.setDrawer(navigationDrawer); |
221 View switcherView = mAccountSwitcher.getView(); | 256 View switcherView = mAccountSwitcher.getView(); |
222 switcherView.setLayoutParams(new LinearLayout.LayoutParams( | 257 switcherView.setLayoutParams(new LinearLayout.LayoutParams( |
223 LinearLayout.LayoutParams.MATCH_PARENT, | 258 LinearLayout.LayoutParams.MATCH_PARENT, |
224 LinearLayout.LayoutParams.WRAP_CONTENT)); | 259 LinearLayout.LayoutParams.WRAP_CONTENT)); |
225 navigationDrawer.addView(switcherView, 0); | 260 navigationDrawer.addView(switcherView, 0); |
226 | 261 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 // Unreachable, but required by Google Java style and findbugs. | 589 // Unreachable, but required by Google Java style and findbugs. |
555 assert false : "Unreached"; | 590 assert false : "Unreached"; |
556 } | 591 } |
557 | 592 |
558 if (dismissProgress && mProgressIndicator != null) { | 593 if (dismissProgress && mProgressIndicator != null) { |
559 mProgressIndicator.dismiss(); | 594 mProgressIndicator.dismiss(); |
560 mProgressIndicator = null; | 595 mProgressIndicator = null; |
561 } | 596 } |
562 } | 597 } |
563 } | 598 } |
OLD | NEW |