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.annotation.Nullable; 26 import androidx.appcompat.app.AlertDialog; 27 28 import com.example.android.support.wear.R; 29 30 /** 31 * Demo for AlertDialog on Wear. 32 */ 33 public class AlertDialogDemo extends Activity { 34 @Override onCreate(@ullable Bundle savedInstanceState)35 protected void onCreate(@Nullable Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 setContentView(R.layout.alert_dialog_demo); 38 39 AlertDialog v7Dialog = createV7Dialog(); 40 android.app.AlertDialog frameworkDialog = createFrameworkDialog(); 41 42 Button v7Trigger = findViewById(R.id.v7_dialog_button); 43 v7Trigger.setOnClickListener(new View.OnClickListener() { 44 @Override 45 public void onClick(View v) { 46 v7Dialog.show(); 47 } 48 }); 49 50 Button frameworkTrigger = findViewById(R.id.framework_dialog_button); 51 frameworkTrigger.setOnClickListener(new View.OnClickListener() { 52 @Override 53 public void onClick(View v) { 54 frameworkDialog.show(); 55 } 56 }); 57 } 58 createV7Dialog()59 private AlertDialog createV7Dialog() { 60 Drawable drawable = getDrawable(R.drawable.app_sample_code); 61 return new AlertDialog.Builder(this) 62 .setTitle("AppCompatDialog") 63 .setMessage("Lorem ipsum dolor...") 64 .setPositiveButton("Ok", null) 65 .setPositiveButtonIcon(drawable) 66 .setNegativeButton("Cancel", null) 67 .create(); 68 } 69 createFrameworkDialog()70 private android.app.AlertDialog createFrameworkDialog() { 71 return new android.app.AlertDialog.Builder(this) 72 .setTitle("FrameworkDialog") 73 .setMessage("Lorem ipsum dolor...") 74 .setPositiveButton("Ok", null) 75 .setNegativeButton("Cancel", null) 76 .create(); 77 } 78 } 79