1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 * Copyright (C) 2016 Mopria Alliance, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.bips.ui;
19
20import android.app.ActionBar;
21import android.app.Activity;
22import android.app.Fragment;
23import android.os.Bundle;
24import android.view.MenuItem;
25
26/**
27 * Launched by system in response to an Add Printer request
28 */
29public class AddPrintersActivity extends Activity {
30    @Override
31    protected void onCreate(Bundle savedInstanceState) {
32        super.onCreate(savedInstanceState);
33        getFragmentManager().beginTransaction()
34                .replace(android.R.id.content, new AddPrintersFragment())
35                .commit();
36
37        ActionBar actionBar = getActionBar();
38        if (actionBar != null) {
39            actionBar.setDisplayHomeAsUpEnabled(true);
40        }
41    }
42
43    @Override
44    public boolean onOptionsItemSelected(MenuItem item) {
45        switch (item.getItemId()) {
46            // Respond to the action bar's Up/Home button
47            case android.R.id.home:
48                onBackPressed();
49                return true;
50        }
51        return super.onOptionsItemSelected(item);
52    }
53
54    @Override
55    public void onRequestPermissionsResult(int requestCode, String[] permissions,
56            int[] grantResults) {
57        Fragment fragment = getFragmentManager().findFragmentById(android.R.id.content);
58        if (fragment != null && fragment instanceof OnPermissionChangeListener) {
59            ((OnPermissionChangeListener) fragment).onPermissionChange();
60        }
61    }
62
63    interface OnPermissionChangeListener {
64        void onPermissionChange();
65    }
66}
67