• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.android.gallery3d.app;
18 
19 import android.os.Bundle;
20 import android.view.Menu;
21 import android.view.MenuInflater;
22 import android.view.MenuItem;
23 import android.view.View;
24 import android.view.View.OnClickListener;
25 import android.view.Window;
26 
27 import com.android.gallery3d.R;
28 import com.android.gallery3d.ui.GLRoot;
29 import com.android.gallery3d.ui.GLRootView;
30 
31 public class PickerActivity extends AbstractGalleryActivity
32         implements OnClickListener {
33 
34     public static final String KEY_ALBUM_PATH = "album-path";
35 
36     @Override
onCreate(Bundle savedInstanceState)37     public void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39 
40         // We show the picker in two ways. One smaller screen we use a full
41         // screen window with an action bar. On larger screen we use a dialog.
42         boolean isDialog = getResources().getBoolean(R.bool.picker_is_dialog);
43 
44         if (!isDialog) {
45             requestWindowFeature(Window.FEATURE_ACTION_BAR);
46             requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
47         }
48 
49         setContentView(R.layout.dialog_picker);
50 
51         if (isDialog) {
52             // In dialog mode, we don't have the action bar to show the
53             // "cancel" action, so we show an additional "cancel" button.
54             View view = findViewById(R.id.cancel);
55             view.setOnClickListener(this);
56             view.setVisibility(View.VISIBLE);
57 
58             // We need this, otherwise the view will be dimmed because it
59             // is "behind" the dialog.
60             ((GLRootView) findViewById(R.id.gl_root_view)).setZOrderOnTop(true);
61         }
62     }
63 
64     @Override
onCreateOptionsMenu(Menu menu)65     public boolean onCreateOptionsMenu(Menu menu) {
66         MenuInflater inflater = getMenuInflater();
67         inflater.inflate(R.menu.pickup, menu);
68         return true;
69     }
70 
71     @Override
onOptionsItemSelected(MenuItem item)72     public boolean onOptionsItemSelected(MenuItem item) {
73         if (item.getItemId() == R.id.action_cancel) {
74             finish();
75             return true;
76         }
77         return super.onOptionsItemSelected(item);
78     }
79 
80     @Override
onClick(View v)81     public void onClick(View v) {
82         if (v.getId() == R.id.cancel) finish();
83     }
84 }
85