Extend DialogActivity API demo to show off new window re-measuring.

Change-Id: Ia04dbf95131d5cffbdd3ae0c22758da7f6d28a1b
This commit is contained in:
Dianne Hackborn
2010-12-02 21:51:11 -08:00
parent 6893c37267
commit ae1d79d3f4
5 changed files with 67 additions and 11 deletions

View File

@@ -75,7 +75,7 @@
<activity android:name=".app.DialogActivity"
android:label="@string/activity_dialog"
android:theme="@android:style/Theme.Dialog">
android:theme="@android:style/Theme.Holo.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />

View File

@@ -17,8 +17,28 @@
<!-- Demonstrates an activity with a dialog theme.
See corresponding Java code com.android.sdk.app.DialogActivity.java. -->
<!-- This screen consists of a single text field that displays some text. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dip" android:gravity="center_horizontal">
<TextView android:id="@+id/text"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="@string/dialog_activity_text"/>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:paddingTop="4dip">
<Button android:id="@+id/add"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/dialog_activity_add">
<requestFocus />
</Button>
<Button android:id="@+id/remove"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/dialog_activity_remove">
</Button>
</LinearLayout>
<LinearLayout android:id="@+id/inner_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:paddingTop="4dip">
</LinearLayout>
</LinearLayout>

View File

@@ -17,7 +17,8 @@
<!-- Demonstrates starting and stopping a local service.
See corresponding Java code com.android.sdk.app.LocalSerice.java. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="4dip"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">

View File

@@ -31,7 +31,10 @@
<string name="activity_dialog">App/Activity/Dialog</string>
<string name="dialog_activity_text">Example of how you can use the
Theme.Dialog theme to make an activity that looks like a
dialog.</string>
dialog. It also has lots of text to show how text wrapping (and
corresponding window size adjustment) can happen in a dialog.</string>
<string name="dialog_activity_add">Add content</string>
<string name="dialog_activity_remove">Remove content</string>
<string name="activity_custom_dialog">App/Activity/Custom Dialog</string>
<string name="custom_dialog_activity_text">Example of how you can use a
custom Theme.Dialog theme to make an activity that looks like a
@@ -372,7 +375,7 @@
<!-- app/dialog examples strings -->
<!-- ============================== -->
<string name="activity_alert_dialog">App/Dialog</string>
<string name="activity_alert_dialog">App/Alert Dialogs</string>
<string name="alert_dialog_two_buttons">OK Cancel dialog with a message</string>
<string name="alert_dialog_two_buttons2">OK Cancel dialog with a long message</string>
<string name="alert_dialog_two_buttons2ultra">OK Cancel dialog with ultra long message</string>

View File

@@ -19,10 +19,17 @@ package com.example.android.apis.app;
// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.example.android.apis.R;
import com.example.android.apis.app.ForegroundService.Controller;
/**
* <h3>Dialog Activity</h3>
@@ -50,5 +57,30 @@ public class DialogActivity extends Activity {
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
android.R.drawable.ic_dialog_alert);
Button button = (Button)findViewById(R.id.add);
button.setOnClickListener(mAddContentListener);
button = (Button)findViewById(R.id.remove);
button.setOnClickListener(mRemoveContentListener);
}
private OnClickListener mAddContentListener = new OnClickListener() {
public void onClick(View v) {
LinearLayout layout = (LinearLayout)findViewById(R.id.inner_content);
ImageView iv = new ImageView(DialogActivity.this);
iv.setImageDrawable(getResources().getDrawable(R.drawable.icon48x48_1));
iv.setPadding(4, 4, 4, 4);
layout.addView(iv);
}
};
private OnClickListener mRemoveContentListener = new OnClickListener() {
public void onClick(View v) {
LinearLayout layout = (LinearLayout)findViewById(R.id.inner_content);
int num = layout.getChildCount();
if (num > 0) {
layout.removeViewAt(num-1);
}
}
};
}