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