Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/NavigationMenuAdapter.java

Issue 2389153003: [remoting android] Close navigation drawer before opening Help/Feedback. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.app.Activity; 7 import android.app.Activity;
8 import android.content.Context; 8 import android.content.Context;
9 import android.graphics.drawable.Drawable; 9 import android.graphics.drawable.Drawable;
10 import android.view.LayoutInflater; 10 import android.view.LayoutInflater;
11 import android.view.View; 11 import android.view.View;
12 import android.view.ViewGroup; 12 import android.view.ViewGroup;
13 import android.widget.AdapterView; 13 import android.widget.AdapterView;
14 import android.widget.ArrayAdapter; 14 import android.widget.ArrayAdapter;
15 import android.widget.ListView; 15 import android.widget.ListView;
16 import android.widget.TextView; 16 import android.widget.TextView;
17 17
18 import org.chromium.base.ApiCompatibilityUtils; 18 import org.chromium.base.ApiCompatibilityUtils;
19 import org.chromium.chromoting.help.HelpContext; 19 import org.chromium.chromoting.help.HelpContext;
20 import org.chromium.chromoting.help.HelpSingleton;
21 20
22 /** 21 /**
23 * Describes the appearance and behavior of the navigation menu. This also imple ments 22 * Describes the appearance and behavior of the navigation menu. This also imple ments
24 * AdapterView.OnItemClickListener so it can be used as the ListView's onItemCli ckListener. 23 * AdapterView.OnItemClickListener so it can be used as the ListView's onItemCli ckListener.
25 */ 24 */
26 public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na vigationMenuItem> 25 public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na vigationMenuItem>
27 implements AdapterView.OnItemClickListener { 26 implements AdapterView.OnItemClickListener {
28 /** 27 /**
29 * Defines a menu item. 28 * Defines a menu item.
30 */ 29 */
31 public static class NavigationMenuItem { 30 public static class NavigationMenuItem {
32 private String mText; 31 private String mText;
33 private Drawable mIcon; 32 private Drawable mIcon;
34 private Runnable mCallback; 33 private Runnable mCallback;
35 34
36 public NavigationMenuItem(String text, Drawable icon, Runnable callback) { 35 public NavigationMenuItem(String text, Drawable icon, Runnable callback) {
37 mText = text; 36 mText = text;
38 mIcon = icon; 37 mIcon = icon;
39 mCallback = callback; 38 mCallback = callback;
40 } 39 }
41 } 40 }
42 41
43 public static ListView createNavigationMenu(final Activity activity) { 42 public static ListView createNavigationMenu(final Chromoting chromoting) {
44 ListView navigationMenu = (ListView) activity.getLayoutInflater() 43 ListView navigationMenu =
45 .inflate(R.layout.navigation_list, null); 44 (ListView) chromoting.getLayoutInflater().inflate(R.layout.navig ation_list, null);
46 45
47 NavigationMenuItem feedbackItem = new NavigationMenuItem( 46 NavigationMenuItem feedbackItem = new NavigationMenuItem(
48 activity.getResources().getString(R.string.actionbar_send_feedba ck), 47 chromoting.getResources().getString(R.string.actionbar_send_feed back),
49 getIcon(activity, R.drawable.ic_announcement), 48 getIcon(chromoting, R.drawable.ic_announcement), new Runnable() {
50 new Runnable() {
51 @Override 49 @Override
52 public void run() { 50 public void run() {
53 HelpSingleton.getInstance().launchFeedback(activity); 51 chromoting.launchFeedback();
54 } 52 }
55 }); 53 });
56 54
57 NavigationMenuItem helpItem = new NavigationMenuItem( 55 NavigationMenuItem helpItem = new NavigationMenuItem(
58 activity.getResources().getString(R.string.actionbar_help), 56 chromoting.getResources().getString(R.string.actionbar_help),
59 getIcon(activity, R.drawable.ic_help), 57 getIcon(chromoting, R.drawable.ic_help), new Runnable() {
60 new Runnable() {
61 @Override 58 @Override
62 public void run() { 59 public void run() {
63 HelpSingleton.getInstance().launchHelp(activity, 60 chromoting.launchHelp(HelpContext.HOST_LIST);
64 HelpContext.HOST_LIST);
65 } 61 }
66 }); 62 });
67 63
68 NavigationMenuItem[] navigationMenuItems = { feedbackItem, helpItem }; 64 NavigationMenuItem[] navigationMenuItems = { feedbackItem, helpItem };
69 NavigationMenuAdapter adapter = new NavigationMenuAdapter(activity, navi gationMenuItems); 65 NavigationMenuAdapter adapter = new NavigationMenuAdapter(chromoting, na vigationMenuItems);
70 navigationMenu.setAdapter(adapter); 66 navigationMenu.setAdapter(adapter);
71 navigationMenu.setOnItemClickListener(adapter); 67 navigationMenu.setOnItemClickListener(adapter);
72 return navigationMenu; 68 return navigationMenu;
73 } 69 }
74 70
75 /** Returns the drawable of |drawableId| that can be used to draw icon for a navigation item. */ 71 /** Returns the drawable of |drawableId| that can be used to draw icon for a navigation item. */
76 private static Drawable getIcon(Activity activity, int drawableId) { 72 private static Drawable getIcon(Activity activity, int drawableId) {
77 Drawable drawable = ApiCompatibilityUtils.getDrawable(activity.getResour ces(), drawableId); 73 Drawable drawable = ApiCompatibilityUtils.getDrawable(activity.getResour ces(), drawableId);
78 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntri nsicHeight()); 74 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntri nsicHeight());
79 return drawable; 75 return drawable;
(...skipping 18 matching lines...) Expand all
98 return convertView; 94 return convertView;
99 } 95 }
100 96
101 97
102 /** AdapterView.OnItemClickListener override. */ 98 /** AdapterView.OnItemClickListener override. */
103 @Override 99 @Override
104 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 100 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
105 getItem(position).mCallback.run(); 101 getItem(position).mCallback.run();
106 } 102 }
107 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698