CredentialsInstallDialog.java revision 122def31973a25d878f33ce59288792aea27a32d
1/*
2 * Copyright (C) 2014 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
17package com.android.certinstaller;
18
19import android.app.AlertDialog;
20import android.app.Activity;
21import android.app.Dialog;
22import android.content.Context;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.os.Bundle;
26import android.content.DialogInterface;
27import android.widget.TextView;
28
29public class CredentialsInstallDialog extends Activity {
30    private static final String NETWORK_NAME = "network_name";
31    private static final String INSTALL_STATE = "install_state";
32
33    @Override
34    protected void onCreate(Bundle savedInstanceState) {
35        super.onCreate(savedInstanceState);
36    }
37
38    @Override
39    protected void onResume() {
40        super.onResume();
41        displayDialog();
42    }
43
44    public void displayDialog() {
45        AlertDialog.Builder builder = new AlertDialog.Builder(this);
46        View layout = getLayoutInflater().inflate(R.layout.credentials_installed_dialog, null);
47        builder.setView(layout);
48        Bundle bundle = getIntent().getExtras();
49        int installState = getIntent().getIntExtra(INSTALL_STATE, 0);
50        TextView text = (TextView) layout.findViewById(R.id.credential_installed_content);
51        if (installState == 1) {
52            String networkName = bundle.getString(NETWORK_NAME);
53            text.setText(String.format(getResources().getString(R.string.install_done), networkName));
54            builder.setTitle(getResources().getString(R.string.install_done_title));
55        } else {
56            text.setText(getResources().getString(R.string.wifi_installer_fail));
57        }
58        builder.setPositiveButton(R.string.done_label, new DialogInterface.OnClickListener() {
59            @Override
60            public void onClick(DialogInterface dialog, int which) {
61                dialog.dismiss();
62                finish();
63            }
64        });
65        builder.create().show();
66    }
67}
68