diff options
author | Ray Chen <raychen@google.com> | 2011-08-24 11:40:04 +0800 |
---|---|---|
committer | Ray Chen <raychen@google.com> | 2011-08-26 20:20:48 +0800 |
commit | 327eeb846fa6b2649db90fc4e5708f7fdcbbfaa2 (patch) | |
tree | 36c467e95a6ccd0d704fb073310c7fbac0fb2721 /src/com/android/gallery3d/ui/DialogDetailsView.java | |
parent | ca69a7dd02057818b7d3d61979561958d6109758 (diff) | |
download | android_packages_apps_Snap-327eeb846fa6b2649db90fc4e5708f7fdcbbfaa2.tar.gz android_packages_apps_Snap-327eeb846fa6b2649db90fc4e5708f7fdcbbfaa2.tar.bz2 android_packages_apps_Snap-327eeb846fa6b2649db90fc4e5708f7fdcbbfaa2.zip |
Fix 5133608 [UI] Details should be displayed as a system dialog in phone UI
Fix 5132798 [UI] Details popup on tablet is incorrectly placed and should not have x icon to close
Fix 5199822 Long press and select "detail" shows details of another item
Change-Id: I0e992ded8a154edb1c7a81b75d0461d5bf309f31
Diffstat (limited to 'src/com/android/gallery3d/ui/DialogDetailsView.java')
-rw-r--r-- | src/com/android/gallery3d/ui/DialogDetailsView.java | 239 |
1 files changed, 239 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/ui/DialogDetailsView.java b/src/com/android/gallery3d/ui/DialogDetailsView.java new file mode 100644 index 000000000..030bc34e8 --- /dev/null +++ b/src/com/android/gallery3d/ui/DialogDetailsView.java @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2011 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.gallery3d.ui; + +import static com.android.gallery3d.ui.DetailsWindowConfig.FONT_SIZE; +import static com.android.gallery3d.ui.DetailsWindowConfig.LEFT_RIGHT_EXTRA_PADDING; +import static com.android.gallery3d.ui.DetailsWindowConfig.LINE_SPACING; +import static com.android.gallery3d.ui.DetailsWindowConfig.PREFERRED_WIDTH; +import static com.android.gallery3d.ui.DetailsWindowConfig.TOP_BOTTOM_EXTRA_PADDING; + +import com.android.gallery3d.R; +import com.android.gallery3d.app.GalleryActivity; +import com.android.gallery3d.common.Utils; +import com.android.gallery3d.data.MediaDetails; +import com.android.gallery3d.ui.DetailsAddressResolver.AddressResolvingListener; +import com.android.gallery3d.ui.DetailsHelper.CloseListener; +import com.android.gallery3d.ui.DetailsHelper.DetailsViewContainer; +import com.android.gallery3d.ui.DetailsHelper.DetailsSource; +import com.android.gallery3d.util.Future; +import com.android.gallery3d.util.FutureListener; +import com.android.gallery3d.util.GalleryUtils; +import com.android.gallery3d.util.ReverseGeocoder; +import com.android.gallery3d.util.ThreadPool.Job; +import com.android.gallery3d.util.ThreadPool.JobContext; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.database.DataSetObserver; +import android.graphics.Color; +import android.graphics.Rect; +import android.location.Address; +import android.os.Handler; +import android.os.Message; +import android.text.format.Formatter; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.View.MeasureSpec; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.Map.Entry; + +public class DialogDetailsView implements DetailsViewContainer { + @SuppressWarnings("unused") + private static final String TAG = "DialogDetailsView"; + + private GalleryActivity mContext; + private DetailsAdapter mAdapter; + private MediaDetails mDetails; + private DetailsSource mSource; + private int mIndex; + private Dialog mDialog; + private int mLocationIndex; + + public DialogDetailsView(GalleryActivity activity, DetailsSource source) { + mContext = activity; + mSource = source; + } + + public void show() { + reloadDetails(mSource.getIndex()); + mDialog.show(); + } + + public void hide() { + mDialog.hide(); + } + + public void reloadDetails(int indexHint) { + int index = mSource.findIndex(indexHint); + if (index == -1) return; + MediaDetails details = mSource.getDetails(); + if (details != null) { + if (mIndex == index && mDetails == details) return; + mIndex = index; + mDetails = details; + setDetails(details); + } + } + + public boolean isVisible() { + return mDialog.isShowing(); + } + + private void setDetails(MediaDetails details) { + mAdapter = new DetailsAdapter(details); + String title = String.format( + mContext.getAndroidContext().getString(R.string.details_title), + mIndex + 1, mSource.size()); + mDialog = new AlertDialog.Builder((Activity) mContext) + .setAdapter(mAdapter, null) + .setTitle(title) + .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + mDialog.dismiss(); + } + }) + .create(); + } + + private class DetailsAdapter extends BaseAdapter implements AddressResolvingListener { + private ArrayList<String> mItems; + + public DetailsAdapter(MediaDetails details) { + Context context = mContext.getAndroidContext(); + mItems = new ArrayList<String>(details.size()); + mLocationIndex = -1; + setDetails(context, details); + } + + private void setDetails(Context context, MediaDetails details) { + for (Entry<Integer, Object> detail : details) { + String value; + switch (detail.getKey()) { + case MediaDetails.INDEX_LOCATION: { + double[] latlng = (double[]) detail.getValue(); + mLocationIndex = mItems.size(); + value = DetailsHelper.resolveAddress(mContext, latlng, mAdapter); + break; + } + case MediaDetails.INDEX_SIZE: { + value = Formatter.formatFileSize( + context, (Long) detail.getValue()); + break; + } + case MediaDetails.INDEX_WHITE_BALANCE: { + value = "1".equals(detail.getValue()) + ? context.getString(R.string.manual) + : context.getString(R.string.auto); + break; + } + case MediaDetails.INDEX_FLASH: { + MediaDetails.FlashState flash = + (MediaDetails.FlashState) detail.getValue(); + // TODO: camera doesn't fill in the complete values, show more information + // when it is fixed. + if (flash.isFlashFired()) { + value = context.getString(R.string.flash_on); + } else { + value = context.getString(R.string.flash_off); + } + break; + } + case MediaDetails.INDEX_EXPOSURE_TIME: { + value = (String) detail.getValue(); + double time = Double.valueOf(value); + if (time < 1.0f) { + value = String.format("1/%d", (int) (0.5f + 1 / time)); + } else { + int integer = (int) time; + time -= integer; + value = String.valueOf(integer) + "''"; + if (time > 0.0001) { + value += String.format(" 1/%d", (int) (0.5f + 1 / time)); + } + } + break; + } + default: { + Object valueObj = detail.getValue(); + // This shouldn't happen, log its key to help us diagnose the problem. + Utils.assertTrue(valueObj != null, "%s's value is Null", + DetailsHelper.getDetailsName(context, detail.getKey())); + value = valueObj.toString(); + } + } + int key = detail.getKey(); + if (details.hasUnit(key)) { + value = String.format("%s : %s %s", DetailsHelper.getDetailsName( + context, key), value, context.getString(details.getUnit(key))); + } else { + value = String.format("%s : %s", DetailsHelper.getDetailsName( + context, key), value); + } + mItems.add(value); + } + } + + public boolean areAllItemsEnabled() { + return false; + } + + public boolean isEnabled(int position) { + return false; + } + + public int getCount() { + return mItems.size(); + } + + public Object getItem(int position) { + return mDetails.getDetail(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + TextView tv; + if (convertView == null) { + tv = (TextView) LayoutInflater.from(mContext.getAndroidContext()).inflate( + R.layout.details, parent, false); + } else { + tv = (TextView) convertView; + } + tv.setText(mItems.get(position)); + return tv; + } + + public void onAddressAvailable(String address) { + mItems.set(mLocationIndex, address); + } + } + + public void setCloseListener(CloseListener listener) { + } +} |