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 com.android.gallery3d.R;
     20 import com.android.gallery3d.ui.GLRoot;
     21 import com.android.gallery3d.ui.GLRootView;
     22 
     23 import android.os.Bundle;
     24 import android.view.Menu;
     25 import android.view.MenuInflater;
     26 import android.view.MenuItem;
     27 import android.view.View;
     28 import android.view.View.OnClickListener;
     29 import android.view.Window;
     30 
     31 public class PickerActivity extends AbstractGalleryActivity
     32         implements OnClickListener {
     33 
     34     public static final String KEY_ALBUM_PATH = "album-path";
     35 
     36     @Override
     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
     65     public boolean onCreateOptionsMenu(Menu menu) {
     66         MenuInflater inflater = getMenuInflater();
     67         inflater.inflate(R.menu.pickup, menu);
     68         return true;
     69     }
     70 
     71     @Override
     72     public boolean onOptionsItemSelected(MenuItem item) {
     73         if (item.getItemId() == R.id.action_cancel) {
     74             finish();
     75             return true;
     76         }
     77         return false;
     78     }
     79 
     80     @Override
     81     public void onBackPressed() {
     82         // send the back event to the top sub-state
     83         GLRoot root = getGLRoot();
     84         root.lockRenderThread();
     85         try {
     86             getStateManager().getTopState().onBackPressed();
     87         } finally {
     88             root.unlockRenderThread();
     89         }
     90     }
     91 
     92     @Override
     93     public void onClick(View v) {
     94         if (v.getId() == R.id.cancel) finish();
     95     }
     96 }
     97