Merge "Add tooltip demo to ApiDemos"

This commit is contained in:
TreeHugger Robot
2016-11-22 22:15:43 +00:00
committed by Android (Google) Code Review
4 changed files with 202 additions and 0 deletions

View File

@@ -2715,6 +2715,13 @@
</intent-filter>
</activity>
<activity android:name=".view.Tooltips" android:label="Views/Tooltips">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<!-- ************************************* -->
<!-- GRAPHICS SAMPLES -->
<!-- ************************************* -->

View File

@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical"
android:tooltip="@string/tooltips_container_tooltip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="20sp"
android:text="@string/tooltips_description" />
<TextView
android:id="@+id/tooltips_code"
android:background="#ccc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:padding="10dp"
android:textSize="16sp"
android:text="@string/tooltips_code_label" />
<TextView
android:background="#ccc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:padding="10dp"
android:textSize="16sp"
android:text="@string/tooltips_resource_label"
android:tooltip="@string/tooltips_resource_tooltip" />
<TextView
android:background="#ccc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:padding="10dp"
android:textSize="16sp"
android:text="@string/tooltips_long_label"
android:tooltip="@string/tooltips_long_tooltip" />
<TextView
android:background="#ccc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_gravity="start|center_vertical"
android:padding="10dp"
android:textSize="16sp"
android:text="@string/tooltips_edge_label"
android:tooltip="@string/tooltips_edge_tooltip" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:background="#ccc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:padding="10dp"
android:textSize="16sp"
android:text="@string/tooltips_above_label"
android:tooltip="@string/tooltips_above_tooltip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:background="#ccc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:padding="10dp"
android:gravity="center"
android:textSize="16sp"
android:text="@string/tooltips_wide_label"
android:tooltip="@string/tooltips_wide_tooltip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:background="#ccc"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:padding="10dp"
android:gravity="center"
android:textSize="16sp"
android:text="@string/tooltips_tall_label"
android:tooltip="@string/tooltips_tall_tooltip" />
<TextView
android:background="#ccc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="4dp"
android:padding="10dp"
android:gravity="center"
android:textSize="16sp"
android:text="@string/tooltips_large_label"
android:tooltip="@string/tooltips_large_tooltip" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -1123,6 +1123,24 @@
<string name="pointer_type_custom_system">Custom (system icon picked in code)</string>
<string name="pointer_type_custom_live">Custom (dynamic image created in code)</string>
<string name="tooltips_container_tooltip">Parent view may have its own tooltip</string>
<string name="tooltips_description">Long press or hover on widgets to see tooltips</string>
<string name="tooltips_code_label">Set in code</string>
<string name="tooltips_resource_label">Set in resource</string>
<string name="tooltips_resource_tooltip">This tooltip is set in resource</string>
<string name="tooltips_long_label">Long tooltip</string>
<string name="tooltips_long_tooltip">An overly long tooltip will be truncated. An overly long tooltip will be truncated. An overly long tooltip will be truncated. An overly long tooltip will be truncated</string>
<string name="tooltips_edge_label">Near the edge</string>
<string name="tooltips_edge_tooltip">A tooltip is always fits inside the app window</string>
<string name="tooltips_above_label">Above placement</string>
<string name="tooltips_above_tooltip">When there is not enough room below, the tooltip goes above</string>
<string name="tooltips_wide_label">Wide widget</string>
<string name="tooltips_wide_tooltip">Wide widget gets a tooltip horizontally aligned to the pointer position</string>
<string name="tooltips_tall_label">Tall\nwidget</string>
<string name="tooltips_tall_tooltip">Tall widget gets a tooltip vertically aligned to the pointer position</string>
<string name="tooltips_large_label">Large widget</string>
<string name="tooltips_large_tooltip">Vertically large widget gets a tooltip aligned to the pointer position</string>
<!-- ============================== -->
<!-- GoogleLogin examples strings -->
<!-- ============================== -->

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2016 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.
*/
package com.example.android.apis.view;
import com.example.android.apis.R;
import android.app.Activity;
import android.os.Bundle;
/**
* A demo for tooltips
*/
public class Tooltips extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tooltips);
findViewById(R.id.tooltips_code).setTooltip("This tooltip is set in code");
}
}