Fully fixed coverflow resizing, added menu, fixed fragment changes.

Change-Id: Iaec671f81dada2dd9c667bde48b34ae2e89a321d
This commit is contained in:
Andrzej J.R. Hunt 2012-07-25 15:42:46 +02:00 committed by Michael Meeks
parent 7c0ddee3f8
commit f656596761
6 changed files with 59 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

View file

@ -19,7 +19,9 @@
android:id="@+id/presentation_slidenumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_gravity="center_horizontal"
android:text="" />
<ImageView
android:id="@+id/presentation_handle"
android:layout_width="fill_parent"

View file

@ -9,7 +9,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_launcher" />
android:src="@drawable/ic_launcher"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/sub_number"

View file

@ -3,7 +3,8 @@
<item
android:id="@+id/actionbar_presentation_submenu"
android:showAsAction="always">
android:showAsAction="always"
android:icon="@drawable/icon_overflow">
<menu>
<item
android:id="@+id/actionbar_presentation_submenu_blank"

View file

@ -38,6 +38,9 @@ public class PresentationFragment extends Fragment {
private CommunicationService mCommunicationService;
private SlideShow mSlideShow;
private float mOriginalCoverflowWidth;
private float mOriginalCoverflowHeight;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mContext = container.getContext();
@ -66,6 +69,9 @@ public class PresentationFragment extends Fragment {
// Call again to set things up if necessary.
setCommunicationService(mCommunicationService);
// Save the height/width for future reference
mOriginalCoverflowHeight = mTopView.getImageHeight();
mOriginalCoverflowWidth = mTopView.getImageWidth();
return v;
}
@ -84,38 +90,51 @@ public class PresentationFragment extends Fragment {
break;
case MotionEvent.ACTION_MOVE:
LayoutParams aParams = mTopView.getLayoutParams();
int aHeightOriginal = mTopView.getHeight();
int aHeight = mTopView.getHeight();
int aViewSize = mLayout.getHeight();
final int DRAG_MARGIN = 120;
// Set Height
aParams.height = aHeight + (int) (aEvent.getY());
int aViewSize = mLayout.getHeight();
if (aParams.height < DRAG_MARGIN) {
aParams.height = DRAG_MARGIN;
} else if (aParams.height > aViewSize - DRAG_MARGIN) {
aParams.height = aViewSize - DRAG_MARGIN;
// Calculate height change, taking limits into account
int aDiff = (int) (aEvent.getY());
System.out.println("Diff1 is :" + aDiff);
if (aDiff + aHeight < DRAG_MARGIN) {
aDiff = DRAG_MARGIN - aHeight;
} else if ((aHeight + aDiff) > (aViewSize - DRAG_MARGIN)) {
aDiff = (aViewSize - DRAG_MARGIN) - aHeight;
}
int aDiff = aParams.height - aHeightOriginal;
mTopView.setLayoutParams(aParams);
// Now deal with the internal height
System.out.println("Before:W:" + mTopView.getImageWidth()
+ ":H:" + mTopView.getImageHeight());
AbstractCoverFlowImageAdapter aAdapter = (AbstractCoverFlowImageAdapter) mTopView
.getAdapter();
int aHeightNew = (int) (mTopView.getImageHeight() + aDiff);
double aRatio = mOriginalCoverflowWidth
/ mOriginalCoverflowHeight;
System.out.println("Diff2 is :" + aDiff);
float aHeightNew = mTopView.getImageHeight() + aDiff;
float aWidthNew = (float) (aRatio * aHeightNew);
// Too wide -- so scale down
if (aWidthNew > mLayout.getWidth() - 50) {
aWidthNew = mLayout.getWidth() - 50;
aHeightNew = (float) (aWidthNew / aRatio);
aDiff = (int) (aHeightNew - mTopView.getImageHeight());
}
// Set the new settings -- it turns out that changing the
// internal height now works, and changing the views height
// is unnecessary / even causes problems.
// aParams.height += aDiff;
// mTopView.setLayoutParams(aParams);
aAdapter.setHeight(aHeightNew);
mTopView.setImageHeight(aHeightNew);
int aWidthNew = aHeightNew * 180 / 150;
aAdapter.setWidth(aWidthNew);
mTopView.setImageWidth(aWidthNew);
// We need to update the view now
aAdapter.notifyDataSetChanged();
System.out.println("After:W:" + mTopView.getImageWidth()
+ ":H:" + mTopView.getImageHeight());
break;
}
// TODO Auto-generated method stub
@ -162,7 +181,7 @@ public class PresentationFragment extends Fragment {
int aSlide = aData.getInt("slide_number");
mTopView.setSelection(aSlide, true);
mNumberText.setText(mSlideShow.getCurrentSlide() + "/"
mNumberText.setText((mSlideShow.getCurrentSlide() + 1) + "/"
+ mSlideShow.getSize());
break;

View file

@ -57,6 +57,15 @@ public class ThumbnailFragment extends Fragment {
return v;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mGrid = null;
mContext = null;
mCurrentImage = null;
mCurrentText = null;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -192,14 +201,14 @@ public class ThumbnailFragment extends Fragment {
}
Bitmap aBitmap = mSlideShow.getImage(position);
if (aBitmap != null) {
aImage.setImageBitmap(aBitmap);
}
// Width
int aWidth = (mGrid.getWidth()) / 3 - 20;
aImage.setMaxWidth(aWidth);
aImage.setScaleType(ScaleType.MATRIX);
aImage.setScaleType(ScaleType.FIT_CENTER);
if (aBitmap != null) {
aImage.setImageBitmap(aBitmap);
}
aText.setText(String.valueOf(position + 1));