| OLD | NEW |
| 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.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; |
| 8 import android.view.LayoutInflater; | 10 import android.view.LayoutInflater; |
| 9 import android.view.View; | 11 import android.view.View; |
| 10 import android.view.ViewGroup; | 12 import android.view.ViewGroup; |
| 11 import android.widget.AdapterView; | 13 import android.widget.AdapterView; |
| 12 import android.widget.ArrayAdapter; | 14 import android.widget.ArrayAdapter; |
| 15 import android.widget.ListView; |
| 16 |
| 17 import org.chromium.chromoting.help.CreditsActivity; |
| 18 import org.chromium.chromoting.help.FeedbackSender; |
| 19 import org.chromium.chromoting.help.HelpContext; |
| 20 import org.chromium.chromoting.help.HelpSingleton; |
| 13 | 21 |
| 14 /** | 22 /** |
| 15 * Describes the appearance and behavior of the navigation menu. This also imple
ments | 23 * Describes the appearance and behavior of the navigation menu. This also imple
ments |
| 16 * AdapterView.OnItemClickListener so it can be used as the ListView's onItemCli
ckListener. | 24 * AdapterView.OnItemClickListener so it can be used as the ListView's onItemCli
ckListener. |
| 17 */ | 25 */ |
| 18 public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na
vigationMenuItem> | 26 public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na
vigationMenuItem> |
| 19 implements AdapterView.OnItemClickListener { | 27 implements AdapterView.OnItemClickListener { |
| 20 /** | 28 /** |
| 21 * Defines a menu item. | 29 * Defines a menu item. |
| 22 */ | 30 */ |
| 23 public static class NavigationMenuItem { | 31 public static class NavigationMenuItem { |
| 24 private int mLayoutResourceId; | 32 private int mLayoutResourceId; |
| 25 private Runnable mCallback; | 33 private Runnable mCallback; |
| 26 public NavigationMenuItem(int layoutResourceId, Runnable callback) { | 34 public NavigationMenuItem(int layoutResourceId, Runnable callback) { |
| 27 mLayoutResourceId = layoutResourceId; | 35 mLayoutResourceId = layoutResourceId; |
| 28 mCallback = callback; | 36 mCallback = callback; |
| 29 } | 37 } |
| 30 } | 38 } |
| 31 | 39 |
| 40 public static ListView createNavigationMenu(final Activity activity) { |
| 41 ListView navigationMenu = (ListView) activity.getLayoutInflater() |
| 42 .inflate(R.layout.navigation_list, null); |
| 43 |
| 44 NavigationMenuItem creditsItem = new NavigationMenuItem(R.menu.credits_l
ist_item, |
| 45 new Runnable() { |
| 46 @Override |
| 47 public void run() { |
| 48 activity.startActivity(new Intent(activity, CreditsActiv
ity.class)); |
| 49 } |
| 50 }); |
| 51 |
| 52 NavigationMenuItem feedbackItem = new NavigationMenuItem(R.menu.feedback
_list_item, |
| 53 new Runnable() { |
| 54 @Override |
| 55 public void run() { |
| 56 FeedbackSender.sendFeedback(activity); |
| 57 } |
| 58 }); |
| 59 |
| 60 NavigationMenuItem helpItem = new NavigationMenuItem(R.menu.help_list_it
em, |
| 61 new Runnable() { |
| 62 @Override |
| 63 public void run() { |
| 64 HelpSingleton.getInstance().launchHelp(activity, |
| 65 HelpContext.HOST_LIST); |
| 66 } |
| 67 }); |
| 68 |
| 69 NavigationMenuItem[] navigationMenuItems = { creditsItem, feedbackItem,
helpItem }; |
| 70 NavigationMenuAdapter adapter = new NavigationMenuAdapter(activity, navi
gationMenuItems); |
| 71 navigationMenu.setAdapter(adapter); |
| 72 navigationMenu.setOnItemClickListener(adapter); |
| 73 return navigationMenu; |
| 74 } |
| 75 |
| 32 public NavigationMenuAdapter(Context context, NavigationMenuItem[] objects)
{ | 76 public NavigationMenuAdapter(Context context, NavigationMenuItem[] objects)
{ |
| 33 super(context, -1, objects); | 77 super(context, -1, objects); |
| 34 } | 78 } |
| 35 | 79 |
| 36 /** Generates a View corresponding to the particular navigation item. */ | 80 /** Generates a View corresponding to the particular navigation item. */ |
| 37 @Override | 81 @Override |
| 38 public View getView(int position, View convertView, ViewGroup parent) { | 82 public View getView(int position, View convertView, ViewGroup parent) { |
| 39 if (convertView == null) { | 83 if (convertView == null) { |
| 40 NavigationMenuItem item = getItem(position); | 84 NavigationMenuItem item = getItem(position); |
| 41 LayoutInflater inflater = | 85 LayoutInflater inflater = |
| 42 (LayoutInflater) getContext().getSystemService(Context.LAYOU
T_INFLATER_SERVICE); | 86 (LayoutInflater) getContext().getSystemService(Context.LAYOU
T_INFLATER_SERVICE); |
| 43 convertView = inflater.inflate(item.mLayoutResourceId, null); | 87 convertView = inflater.inflate(item.mLayoutResourceId, null); |
| 44 } | 88 } |
| 45 return convertView; | 89 return convertView; |
| 46 } | 90 } |
| 47 | 91 |
| 48 | 92 |
| 49 /** AdapterView.OnItemClickListener override. */ | 93 /** AdapterView.OnItemClickListener override. */ |
| 50 @Override | 94 @Override |
| 51 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { | 95 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { |
| 52 getItem(position).mCallback.run(); | 96 getItem(position).mCallback.run(); |
| 53 } | 97 } |
| 54 } | 98 } |
| OLD | NEW |