diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2011-09-07 16:38:40 -0700 |
---|---|---|
committer | Svetoslav Ganov <svetoslavganov@google.com> | 2011-09-08 18:19:13 -0700 |
commit | f2e754002166b8126e6faf8c494da5835432d572 (patch) | |
tree | 6336b979a274ff8fa7f4608ec8ad11af673fa9ec /core/java/android/widget | |
parent | 5e8752595f7a3d3dd1e0d469ac275295e38bcfe1 (diff) | |
download | frameworks_base-f2e754002166b8126e6faf8c494da5835432d572.zip frameworks_base-f2e754002166b8126e6faf8c494da5835432d572.tar.gz frameworks_base-f2e754002166b8126e6faf8c494da5835432d572.tar.bz2 |
Update the sharing UI according to latest UX specs.
bug:3362473
Change-Id: Ic302c289e28061f53446f98e5b97573d57d9cfb8
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/ActivityChooserModel.java | 11 | ||||
-rw-r--r-- | core/java/android/widget/ActivityChooserView.java | 59 |
2 files changed, 52 insertions, 18 deletions
diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java index 9fea506..bc44521 100644 --- a/core/java/android/widget/ActivityChooserModel.java +++ b/core/java/android/widget/ActivityChooserModel.java @@ -663,6 +663,17 @@ public class ActivityChooserModel extends DataSetObservable { } } + /** + * Gets the history size. + * + * @return The history size. + */ + public int getHistorySize() { + synchronized (mInstanceLock) { + return mHistoricalRecords.size(); + } + } + @Override protected void finalize() throws Throwable { super.finalize(); diff --git a/core/java/android/widget/ActivityChooserView.java b/core/java/android/widget/ActivityChooserView.java index fcc7938..312303d 100644 --- a/core/java/android/widget/ActivityChooserView.java +++ b/core/java/android/widget/ActivityChooserView.java @@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; @@ -76,6 +77,11 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod private final LinearLayout mActivityChooserContent; /** + * Stores the background drawable to allow hiding and latter showing. + */ + private final Drawable mActivityChooserContentBackground; + + /** * The expand activities action button; */ private final FrameLayout mExpandActivityOverflowButton; @@ -194,12 +200,15 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod Drawable expandActivityOverflowButtonDrawable = attributesArray.getDrawable( R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable); + attributesArray.recycle(); + LayoutInflater inflater = LayoutInflater.from(mContext); inflater.inflate(R.layout.activity_chooser_view, this, true); mCallbacks = new Callbacks(); mActivityChooserContent = (LinearLayout) findViewById(R.id.activity_chooser_view_content); + mActivityChooserContentBackground = mActivityChooserContent.getBackground(); mDefaultActivityButton = (FrameLayout) findViewById(R.id.default_activity_button); mDefaultActivityButton.setOnClickListener(mCallbacks); @@ -217,7 +226,7 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod @Override public void onChanged() { super.onChanged(); - updateButtons(); + updateAppearance(); } }); @@ -352,9 +361,16 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - mActivityChooserContent.measure(widthMeasureSpec, heightMeasureSpec); - setMeasuredDimension(mActivityChooserContent.getMeasuredWidth(), - mActivityChooserContent.getMeasuredHeight()); + View child = mActivityChooserContent; + // If the default action is not visible we want to be as tall as the + // ActionBar so if this widget is used in the latter it will look as + // a normal action button. + if (mDefaultActivityButton.getVisibility() != VISIBLE) { + heightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), + MeasureSpec.EXACTLY); + } + measureChild(child, widthMeasureSpec, heightMeasureSpec); + setMeasuredDimension(child.getMeasuredWidth(), child.getMeasuredHeight()); } @Override @@ -367,11 +383,6 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod } } - @Override - protected void onDraw(Canvas canvas) { - mActivityChooserContent.onDraw(canvas); - } - public ActivityChooserModel getDataModel() { return mAdapter.getDataModel(); } @@ -417,21 +428,29 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod /** * Updates the buttons state. */ - private void updateButtons() { + private void updateAppearance() { + // Expand overflow button. + if (mAdapter.getCount() > 0) { + mExpandActivityOverflowButton.setEnabled(true); + } else { + mExpandActivityOverflowButton.setEnabled(false); + } + // Default activity button. final int activityCount = mAdapter.getActivityCount(); - if (activityCount > 0) { + final int historySize = mAdapter.getHistorySize(); + if (activityCount > 0 && historySize > 0) { mDefaultActivityButton.setVisibility(VISIBLE); - if (mAdapter.getCount() > 0) { - mExpandActivityOverflowButton.setEnabled(true); - } else { - mExpandActivityOverflowButton.setEnabled(false); - } ResolveInfo activity = mAdapter.getDefaultActivity(); PackageManager packageManager = mContext.getPackageManager(); mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager)); } else { - mDefaultActivityButton.setVisibility(View.INVISIBLE); - mExpandActivityOverflowButton.setEnabled(false); + mDefaultActivityButton.setVisibility(View.GONE); + } + // Activity chooser content. + if (mDefaultActivityButton.getVisibility() == VISIBLE) { + mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground); + } else { + mActivityChooserContent.setBackgroundDrawable(null); } } @@ -678,6 +697,10 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod return mDataModel.getActivityCount(); } + public int getHistorySize() { + return mDataModel.getHistorySize(); + } + public int getMaxActivityCount() { return mMaxActivityCount; } |