Skip to content

Commit

Permalink
[Remoting Android] Put Icons and Credits on Navigation Menu
Browse files Browse the repository at this point in the history
* Add icon to match the design of the account switcher.
* Add Credits on the navigation menu.

BUG=548929

Review-Url: https://codereview.chromium.org/1997793002
Cr-Commit-Position: refs/heads/master@{#394998}
  • Loading branch information
ywh233 authored and Commit bot committed May 20, 2016
1 parent 7b85582 commit a217e5a
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 23 deletions.
1 change: 1 addition & 0 deletions remoting/android/client_java_tmpl.gni
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ template("remoting_android_client_java_tmpl") {
"HostListAdapter.java",
"HostListManager.java",
"InputStrategyInterface.java",
"NavigationMenuAdapter.java",
"OAuthTokenConsumer.java",
"RenderData.java",
"SessionAuthenticator.java",
Expand Down
Binary file added remoting/android/java/res/drawable-hdpi/ic_help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added remoting/android/java/res/drawable-hdpi/ic_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added remoting/android/java/res/drawable-mdpi/ic_help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added remoting/android/java/res/drawable-mdpi/ic_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added remoting/android/java/res/drawable-xhdpi/ic_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions remoting/android/java/res/layout/navigation_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- 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.
-->

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:divider="@null"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingTop="12dp"
android:paddingBottom="12dp"/>
18 changes: 18 additions & 0 deletions remoting/android/java/res/menu/credits_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:drawablePadding="32dp"
android:drawableStart="@drawable/ic_info"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="16dp"
android:paddingBottom="20dp"
android:text="@string/credits"
style="@style/NavigationTextStyle"/>
18 changes: 18 additions & 0 deletions remoting/android/java/res/menu/help_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:drawablePadding="32dp"
android:drawableStart="@drawable/ic_help"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="16dp"
android:paddingBottom="20dp"
android:text="@string/actionbar_help"
style="@style/NavigationTextStyle"/>
54 changes: 31 additions & 23 deletions remoting/android/java/src/org/chromium/chromoting/Chromoting.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Log;
import org.chromium.chromoting.NavigationMenuAdapter.NavigationMenuItem;
import org.chromium.chromoting.accountswitcher.AccountSwitcher;
import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory;
import org.chromium.chromoting.base.OAuthTokenFetcher;
import org.chromium.chromoting.help.CreditsActivity;
import org.chromium.chromoting.help.HelpContext;
import org.chromium.chromoting.help.HelpSingleton;
import org.chromium.chromoting.jni.Client;
Expand Down Expand Up @@ -170,6 +172,34 @@ private void updateHostListView() {
mProgressView.setVisibility(View.GONE);
}

private ListView createNavigationMenu() {
ListView navigationMenu = (ListView) getLayoutInflater()
.inflate(R.layout.navigation_list, null);

NavigationMenuItem helpItem = new NavigationMenuItem(R.menu.help_list_item,
new Runnable() {
@Override
public void run() {
HelpSingleton.getInstance().launchHelp(Chromoting.this,
HelpContext.HOST_LIST);
}
});

NavigationMenuItem creditsItem = new NavigationMenuItem(R.menu.credits_list_item,
new Runnable() {
@Override
public void run() {
startActivity(new Intent(Chromoting.this, CreditsActivity.class));
}
});

NavigationMenuItem[] navigationMenuItems = { helpItem, creditsItem };
NavigationMenuAdapter adapter = new NavigationMenuAdapter(this, navigationMenuItems);
navigationMenu.setAdapter(adapter);
navigationMenu.setOnItemClickListener(adapter);
return navigationMenu;
}

/**
* Called when the activity is first created. Loads the native library and requests an
* authentication token from the system.
Expand Down Expand Up @@ -240,30 +270,8 @@ public void onClick(View view) {
ChromotingUtil.getColorAttribute(this, R.attr.colorControlNormal));
getSupportActionBar().setHomeAsUpIndicator(menuIcon);

ListView navigationMenu = new ListView(this);
navigationMenu.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
navigationMenu.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));

String[] navigationMenuItems = new String[] {
getString(R.string.actionbar_help)
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.navigation_list_item,
navigationMenuItems);
navigationMenu.setAdapter(adapter);
navigationMenu.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
HelpSingleton.getInstance().launchHelp(Chromoting.this,
HelpContext.HOST_LIST);
}
});

mAccountSwitcher = AccountSwitcherFactory.getInstance().createAccountSwitcher(this, this);
mAccountSwitcher.setNavigation(navigationMenu);
mAccountSwitcher.setNavigation(createNavigationMenu());
LinearLayout navigationDrawer = (LinearLayout) findViewById(R.id.navigation_drawer);
mAccountSwitcher.setDrawer(navigationDrawer);
View switcherView = mAccountSwitcher.getView();
Expand Down
Original file line number Diff line number Diff line change
@@ -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. This also implements
* AdapterView.OnItemClickListener so it can be used as the ListView's 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();
}
}

0 comments on commit a217e5a

Please sign in to comment.