diff options
author | John Reck <jreck@google.com> | 2013-02-15 14:32:08 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2013-02-22 15:09:35 -0800 |
commit | 608ef5cf3a15f235aa7b6d80924edbdb0fda365b (patch) | |
tree | fd5dbfe11a54c6d6fa4759a54464a69f1bad7e18 /src/com/android/photos/GalleryActivity.java | |
parent | f3e14d196191672129e2897e25627cc41f5f6534 (diff) | |
download | android_packages_apps_Snap-608ef5cf3a15f235aa7b6d80924edbdb0fda365b.tar.gz android_packages_apps_Snap-608ef5cf3a15f235aa7b6d80924edbdb0fda365b.tar.bz2 android_packages_apps_Snap-608ef5cf3a15f235aa7b6d80924edbdb0fda365b.zip |
Start of photos
Change-Id: Id53dd96d8873e0fe6c2685e07cd7bdc0cde7ea75
Diffstat (limited to 'src/com/android/photos/GalleryActivity.java')
-rw-r--r-- | src/com/android/photos/GalleryActivity.java | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/com/android/photos/GalleryActivity.java b/src/com/android/photos/GalleryActivity.java new file mode 100644 index 000000000..46b5140fb --- /dev/null +++ b/src/com/android/photos/GalleryActivity.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.photos; + +import android.app.ActionBar; +import android.app.ActionBar.Tab; +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentTransaction; +import android.content.Intent; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +import com.android.camera.CameraActivity; +import com.android.gallery3d.R; + +public class GalleryActivity extends Activity { + + private final String FTAG_PHOTOSET = "PhotoSet"; + private final String FTAG_ALBUMSET = "AlbumSet"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setupActionBar(); + } + + private void setupActionBar() { + ActionBar ab = getActionBar(); + ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + ab.setDisplayShowHomeEnabled(false); + ab.setDisplayShowTitleEnabled(false); + Tab tab = ab.newTab(); + tab.setText(R.string.tab_photos); + tab.setTabListener(new TabListener<PhotoSetFragment>(this, + FTAG_PHOTOSET, PhotoSetFragment.class)); + ab.addTab(tab, true); + tab = ab.newTab(); + tab.setText(R.string.tab_albums); + tab.setTabListener(new TabListener<AlbumSetFragment>(this, + FTAG_ALBUMSET, AlbumSetFragment.class)); + ab.addTab(tab); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.gallery, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_camera: + Intent intent = new Intent(this, CameraActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private static class TabListener<T extends Fragment> implements ActionBar.TabListener { + private Fragment mFragment; + private final Activity mActivity; + private final String mTag; + private final Class<T> mClass; + + /** Constructor used each time a new tab is created. + * @param activity The host Activity, used to instantiate the fragment + * @param tag The identifier tag for the fragment + * @param clz The fragment's Class, used to instantiate the fragment + */ + public TabListener(Activity activity, String tag, Class<T> clz) { + mActivity = activity; + mTag = tag; + mClass = clz; + } + + /* The following are each of the ActionBar.TabListener callbacks */ + + @Override + public void onTabSelected(Tab tab, FragmentTransaction ft) { + // Check if the fragment is already initialized + if (mFragment == null) { + // If not, instantiate and add it to the activity + mFragment = Fragment.instantiate(mActivity, mClass.getName()); + ft.add(android.R.id.content, mFragment, mTag); + } else { + // If it exists, simply attach it in order to show it + ft.attach(mFragment); + } + } + + @Override + public void onTabUnselected(Tab tab, FragmentTransaction ft) { + if (mFragment != null) { + // Detach the fragment, because another one is being attached + ft.detach(mFragment); + } + } + + @Override + public void onTabReselected(Tab tab, FragmentTransaction ft) { + // User selected the already selected tab. Usually do nothing. + } + } +} |