Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chromoting; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 import android.view.LayoutInflater; | |
| 9 import android.view.View; | |
| 10 import android.view.ViewGroup; | |
| 11 import android.widget.AdapterView; | |
| 12 import android.widget.ArrayAdapter; | |
| 13 | |
| 14 /** | |
| 15 * Describes the appearance and behavior of the navigation menu. Please set this to both Adapter and | |
|
Lambros
2016/05/20 01:39:25
For the second sentence, maybe say:
This also impl
Yuwei
2016/05/20 03:13:51
Done.
| |
| 16 * OnItemClickListener. | |
| 17 */ | |
| 18 public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na vigationMenuItem> | |
| 19 implements AdapterView.OnItemClickListener { | |
| 20 /** | |
| 21 * Defines a menu item. | |
| 22 */ | |
| 23 public static class NavigationMenuItem { | |
| 24 private int mLayoutResourceId; | |
| 25 private Runnable mCallback; | |
| 26 public NavigationMenuItem(int layoutResourceId, Runnable callback) { | |
| 27 mLayoutResourceId = layoutResourceId; | |
| 28 mCallback = callback; | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 public NavigationMenuAdapter(Context context, NavigationMenuItem[] objects) { | |
| 33 super(context, -1, objects); | |
| 34 } | |
| 35 | |
| 36 /** Generates a View corresponding to the particular navigation item. */ | |
| 37 @Override | |
| 38 public View getView(int position, View convertView, ViewGroup parent) { | |
| 39 if (convertView == null) { | |
| 40 NavigationMenuItem item = getItem(position); | |
| 41 LayoutInflater inflater = | |
| 42 (LayoutInflater) getContext().getSystemService(Context.LAYOU T_INFLATER_SERVICE); | |
| 43 convertView = inflater.inflate(item.mLayoutResourceId, null); | |
| 44 } | |
| 45 return convertView; | |
| 46 } | |
| 47 | |
| 48 | |
| 49 /** AdapterView.OnItemClickListener override. */ | |
| 50 @Override | |
| 51 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
| 52 getItem(position).mCallback.run(); | |
| 53 } | |
| 54 } | |
| OLD | NEW |