blob: de3a0d04dd29931d34a8892c55b9f49210876516 [file] [log] [blame]
/*
* Copyright (C) 2020 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.inlinefillservice;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
/**
* The activity which will be open when the inline suggestion is long pressed. It shows a dialog
* that describes the source of the suggestion.
*/
public class AttributionDialogActivity extends Activity {
static final String KEY_MSG = "AttributionDialogActivity:msg";
static final String DEFAULT_MSG = "Hello";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Intent intent = getIntent();
String msg = DEFAULT_MSG;
if (intent != null) {
msg = intent.getStringExtra(KEY_MSG);
}
Dialog dialog = createDialog(msg);
dialog.setOnDismissListener(dialog1 -> finish());
dialog.show();
}
private Dialog createDialog(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setMessage("The suggestions are generated by the InlineFillService. " + msg)
.setNegativeButton(
"Settings",
(dialog, id) -> {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
})
.setPositiveButton(
"Got it",
(dialog, id) -> {
// User cancelled the dialog
});
return builder.create();
}
}