Chromium Code Reviews| Index: remoting/android/java/src/org/chromium/chromoting/NavigationMenuAdapter.java |
| diff --git a/remoting/android/java/src/org/chromium/chromoting/NavigationMenuAdapter.java b/remoting/android/java/src/org/chromium/chromoting/NavigationMenuAdapter.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f8f3702233bc9d4006892a8113f5f7f55ba1d01f |
| --- /dev/null |
| +++ b/remoting/android/java/src/org/chromium/chromoting/NavigationMenuAdapter.java |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chromoting; |
| + |
| +import android.content.Context; |
| +import android.view.LayoutInflater; |
| +import android.view.View; |
| +import android.view.ViewGroup; |
| +import android.widget.AdapterView; |
| +import android.widget.ArrayAdapter; |
| + |
| +/** |
| + * 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.
|
| + * OnItemClickListener. |
| + */ |
| +public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.NavigationMenuItem> |
| + implements AdapterView.OnItemClickListener { |
| + /** |
| + * Defines a menu item. |
| + */ |
| + public static class NavigationMenuItem { |
| + private int mLayoutResourceId; |
| + private Runnable mCallback; |
| + public NavigationMenuItem(int layoutResourceId, Runnable callback) { |
| + mLayoutResourceId = layoutResourceId; |
| + mCallback = callback; |
| + } |
| + } |
| + |
| + public NavigationMenuAdapter(Context context, NavigationMenuItem[] objects) { |
| + super(context, -1, objects); |
| + } |
| + |
| + /** Generates a View corresponding to the particular navigation item. */ |
| + @Override |
| + public View getView(int position, View convertView, ViewGroup parent) { |
| + if (convertView == null) { |
| + NavigationMenuItem item = getItem(position); |
| + LayoutInflater inflater = |
| + (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| + convertView = inflater.inflate(item.mLayoutResourceId, null); |
| + } |
| + return convertView; |
| + } |
| + |
| + |
| + /** AdapterView.OnItemClickListener override. */ |
| + @Override |
| + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| + getItem(position).mCallback.run(); |
| + } |
| +} |