Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a70c57cf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Show help icon in actionbar"

parents 25e333cb c93dadac
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2017 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?android:attr/colorControlNormal">
    <path
        android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"
        android:fillColor="#FFFFFF"/>
</vector>
+4 −2
Original line number Diff line number Diff line
@@ -76,12 +76,14 @@ public class HelpUtils {
    public static boolean prepareHelpMenuItem(Activity activity, Menu menu, String helpUri,
            String backupContext) {
        MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_feedback_label);
        helpItem.setIcon(R.drawable.ic_help_actionbar);
        return prepareHelpMenuItem(activity, helpItem, helpUri, backupContext);
    }

    public static boolean prepareHelpMenuItem(Activity activity, Menu menu, int helpUriResource,
            String backupContext) {
        MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_feedback_label);
        helpItem.setIcon(R.drawable.ic_help_actionbar);
        return prepareHelpMenuItem(activity, helpItem, activity.getString(helpUriResource),
                backupContext);
    }
@@ -125,7 +127,7 @@ public class HelpUtils {
                        return true;
                    }
                });
                helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                helpMenuItem.setVisible(true);
            } else {
                helpMenuItem.setVisible(false);
@@ -209,7 +211,7 @@ public class HelpUtils {
     * of the app's package as gotten via the context.
     * @return the uri with added query parameters
     */
    public static Uri uriWithAddedParameters(Context context, Uri baseUri) {
    private static Uri uriWithAddedParameters(Context context, Uri baseUri) {
        Uri.Builder builder = baseUri.buildUpon();

        // Add in the preferred language
+47 −1
Original line number Diff line number Diff line
@@ -16,10 +16,18 @@

package com.android.settingslib;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.provider.Settings;
import android.view.MenuItem;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -27,11 +35,14 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
@@ -40,6 +51,7 @@ import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class HelpUtilsTest {
    private static final String TEST_HELP_URL = "intent:#Intent;action=com.android.test;end";
    private static final String PACKAGE_NAME_KEY = "package-name-key";
    private static final String PACKAGE_NAME_VALUE = "package-name-value";
    private static final String HELP_INTENT_EXTRA_KEY = "help-intent-extra";
@@ -49,6 +61,11 @@ public class HelpUtilsTest {

    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
    private Context mContext;
    @Mock
    private Activity mActivity;
    @Mock
    private PackageManager mPackageManager;


    @Before
    public void setUp() {
@@ -65,6 +82,8 @@ public class HelpUtilsTest {
                .thenReturn(FEEDBACK_INTENT_EXTRA_KEY);
        when(mContext.getResources().getString(R.string.config_feedbackIntentNameKey))
                .thenReturn(FEEDBACK_INTENT_NAME_KEY);
        when(mActivity.getPackageManager()).thenReturn(mPackageManager);


    }

@@ -127,4 +146,31 @@ public class HelpUtilsTest {
        assertThat(intent.hasExtra(FEEDBACK_INTENT_EXTRA_KEY)).isFalse();
        assertThat(intent.hasExtra(FEEDBACK_INTENT_NAME_KEY)).isFalse();
    }

    @Test
    public void prepareHelpMenuItem_shouldShowIcon() {
        Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(),
                Settings.Global.DEVICE_PROVISIONED, 1);
        final Resources res = mock(Resources.class);
        final ResolveInfo resolveInfo = new ResolveInfo();
        resolveInfo.activityInfo = new ActivityInfo();
        resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
        resolveInfo.activityInfo.applicationInfo.packageName = "pkg";
        resolveInfo.activityInfo.name = "name";
        final MenuItem item = mock(MenuItem.class);


        when(mActivity.getContentResolver())
                .thenReturn(RuntimeEnvironment.application.getContentResolver());
        when(mActivity.getResources()).thenReturn(res);
        when(mActivity.obtainStyledAttributes(any(int[].class)))
                .thenReturn(mock(TypedArray.class));
        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
                .thenReturn(resolveInfo);

        HelpUtils.prepareHelpMenuItem(mActivity, item, TEST_HELP_URL, "backup_url");

        verify(item).setVisible(true);
        verify(item).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
}
 No newline at end of file