1 /* 2 * Copyright (C) 2020 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.inlinefillservice; 18 19 import android.app.Activity; 20 import android.app.AlertDialog; 21 import android.app.Dialog; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.view.WindowManager; 25 26 /** 27 * The activity which will be open when the inline suggestion is long pressed. It shows a dialog 28 * that describes the source of the suggestion. 29 */ 30 public class AttributionDialogActivity extends Activity { 31 static final String KEY_MSG = "AttributionDialogActivity:msg"; 32 static final String DEFAULT_MSG = "Hello"; 33 34 @Override onCreate(Bundle savedInstanceState)35 protected void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 38 Intent intent = getIntent(); 39 String msg = DEFAULT_MSG; 40 if (intent != null) { 41 msg = intent.getStringExtra(KEY_MSG); 42 } 43 Dialog dialog = createDialog(msg); 44 dialog.setOnDismissListener(dialog1 -> finish()); 45 dialog.show(); 46 } 47 createDialog(String msg)48 private Dialog createDialog(String msg) { 49 AlertDialog.Builder builder = new AlertDialog.Builder(this); 50 builder 51 .setMessage("The suggestions are generated by the InlineFillService. " + msg) 52 .setNegativeButton( 53 "Settings", 54 (dialog, id) -> { 55 Intent intent = new Intent(this, SettingsActivity.class); 56 startActivity(intent); 57 }) 58 .setPositiveButton( 59 "Got it", 60 (dialog, id) -> { 61 // User cancelled the dialog 62 }); 63 return builder.create(); 64 } 65 } 66