1f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein/*
2f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Copyright (C) 2011 Google Inc.
3f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Licensed to The Android Open Source Project.
4f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *
5f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Licensed under the Apache License, Version 2.0 (the "License");
6f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * you may not use this file except in compliance with the License.
7f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * You may obtain a copy of the License at
8f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *
9f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *      http://www.apache.org/licenses/LICENSE-2.0
10f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *
11f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Unless required by applicable law or agreed to in writing, software
12f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * distributed under the License is distributed on an "AS IS" BASIS,
13f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * See the License for the specific language governing permissions and
15f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * limitations under the License.
16f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */
17f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
18f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinpackage com.android.ex.photo;
19f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
2099f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdonimport android.content.Context;
21cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sappersteinimport android.content.Intent;
22f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport android.os.Bundle;
236c542fc4c0d371a7792cb840a0c3d948fb5c47d1Scott Kennedyimport android.support.annotation.Nullable;
24112d29fe9f30d1237a1c8ac1ecc3740879c8c9cePaul Westbrookimport android.support.v4.app.FragmentActivity;
25cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sappersteinimport android.view.Menu;
265f0775af25a40843a2c68d67d694945d88514555Andrew Sappersteinimport android.view.MenuItem;
27f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
28f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein/**
29f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Activity to view the contents of an album.
30f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */
31bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwoodpublic class PhotoViewActivity extends FragmentActivity
32bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        implements PhotoViewController.ActivityInterface {
33f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
345f0775af25a40843a2c68d67d694945d88514555Andrew Sapperstein    private PhotoViewController mController;
35bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    private ActionBarWrapper mActionBar;
3699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon
37f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    @Override
386c542fc4c0d371a7792cb840a0c3d948fb5c47d1Scott Kennedy    protected void onCreate(@Nullable Bundle savedInstanceState) {
39f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        super.onCreate(savedInstanceState);
40bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        mController = createController();
41bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        mController.onCreate(savedInstanceState);
42bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    }
43f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
44bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    public PhotoViewController createController() {
45bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        return new PhotoViewController(this);
46bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    }
47ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
48bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    @Override
49bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    public PhotoViewController getController() {
50bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        return mController;
51f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
52f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
53f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    @Override
54cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    protected void onStart() {
55cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        super.onStart();
56cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        mController.onStart();
57cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    }
58cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein
59cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    @Override
60f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    protected void onResume() {
61f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        super.onResume();
62bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        mController.onResume();
63f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
64f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
65f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    @Override
66f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    protected void onPause() {
67bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        mController.onPause();
68f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        super.onPause();
69f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
70f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
71f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    @Override
72cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    protected void onStop() {
73cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        mController.onStop();
74cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        super.onStop();
75cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    }
76cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein
77cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    @Override
78e0518c6761ab4b25a09c1cf264e13fb1a13ee233Tony Mantler    protected void onDestroy() {
79bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        mController.onDestroy();
80e0518c6761ab4b25a09c1cf264e13fb1a13ee233Tony Mantler        super.onDestroy();
81e0518c6761ab4b25a09c1cf264e13fb1a13ee233Tony Mantler    }
82e0518c6761ab4b25a09c1cf264e13fb1a13ee233Tony Mantler
83e0518c6761ab4b25a09c1cf264e13fb1a13ee233Tony Mantler    @Override
84f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public void onBackPressed() {
85bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        if (!mController.onBackPressed()) {
86bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood            super.onBackPressed();
87f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
88f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
89f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
90f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    @Override
91f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public void onSaveInstanceState(Bundle outState) {
92f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        super.onSaveInstanceState(outState);
93bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        mController.onSaveInstanceState(outState);
94f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
95f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
96bd8b47b147f29f196f37d66ccb561d40414ab5b6Adam Copp    @Override
97cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    public boolean onCreateOptionsMenu(Menu menu) {
98cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        return mController.onCreateOptionsMenu(menu) || super.onCreateOptionsMenu(menu);
99cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    }
100cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein
101cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    @Override
102cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    public boolean onPrepareOptionsMenu(Menu menu) {
103cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        return mController.onPrepareOptionsMenu(menu) || super.onPrepareOptionsMenu(menu);
104cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    }
105cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein
106cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    @Override
107bd8b47b147f29f196f37d66ccb561d40414ab5b6Adam Copp    public boolean onOptionsItemSelected(MenuItem item) {
108cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        return mController.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
109cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    }
110cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein
111cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    @Override
112cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
113cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        super.onActivityResult(requestCode, resultCode, data);
114cd95597f2dfc0760a105a87d16664e56ca1a4afeAndrew Sapperstein        mController.onActivityResult(requestCode, resultCode, data);
115150e623129eef49467f1d6f67649e4636a4513f2Andrew Sapperstein    }
1160ab3e0cf9cbb5751a276e4c2555640a0e8173b5fAdam Copp
1170bf849421d303e05c600cdcd7dab73cc84809a36Mark Wei    @Override
118bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    public Context getContext() {
119bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        return this;
12013ea5dd3a7a3ab4214c6c5dea72a14ccd434d4b1Martin Hibdon    }
12113ea5dd3a7a3ab4214c6c5dea72a14ccd434d4b1Martin Hibdon
122ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon    @Override
123bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    public ActionBarInterface getActionBarInterface() {
124bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        if (mActionBar == null) {
125bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood            mActionBar = new ActionBarWrapper(getActionBar());
12618c85692c141d3a0266dfe88f16f41ae1f20d13eMartin Hibdon        }
127bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        return mActionBar;
1285f0775af25a40843a2c68d67d694945d88514555Andrew Sapperstein    }
1295f0775af25a40843a2c68d67d694945d88514555Andrew Sapperstein
130f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein}
131