1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.support.wear.app; 18 19 import android.app.Activity; 20 import android.graphics.drawable.Drawable; 21 import android.os.Bundle; 22 import android.view.View; 23 import android.widget.Button; 24 25 import androidx.appcompat.app.AlertDialog; 26 27 import com.example.android.support.wear.R; 28 29 import org.jspecify.annotations.Nullable; 30 31 /** 32 * Demo for AlertDialog on Wear. 33 */ 34 public class AlertDialogDemo extends Activity { 35 @Override onCreate(@ullable Bundle savedInstanceState)36 protected void onCreate(@Nullable Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 setContentView(R.layout.alert_dialog_demo); 39 40 AlertDialog v7Dialog = createV7Dialog(); 41 android.app.AlertDialog frameworkDialog = createFrameworkDialog(); 42 43 Button v7Trigger = findViewById(R.id.v7_dialog_button); 44 v7Trigger.setOnClickListener(new View.OnClickListener() { 45 @Override 46 public void onClick(View v) { 47 v7Dialog.show(); 48 } 49 }); 50 51 Button frameworkTrigger = findViewById(R.id.framework_dialog_button); 52 frameworkTrigger.setOnClickListener(new View.OnClickListener() { 53 @Override 54 public void onClick(View v) { 55 frameworkDialog.show(); 56 } 57 }); 58 } 59 createV7Dialog()60 private AlertDialog createV7Dialog() { 61 Drawable drawable = getDrawable(R.drawable.app_sample_code); 62 return new AlertDialog.Builder(this) 63 .setTitle("AppCompatDialog") 64 .setMessage("Lorem ipsum dolor...") 65 .setPositiveButton("Ok", null) 66 .setPositiveButtonIcon(drawable) 67 .setNegativeButton("Cancel", null) 68 .create(); 69 } 70 createFrameworkDialog()71 private android.app.AlertDialog createFrameworkDialog() { 72 return new android.app.AlertDialog.Builder(this) 73 .setTitle("FrameworkDialog") 74 .setMessage("Lorem ipsum dolor...") 75 .setPositiveButton("Ok", null) 76 .setNegativeButton("Cancel", null) 77 .create(); 78 } 79 } 80