Skip to content

Commit

Permalink
Fix for ICS
Browse files Browse the repository at this point in the history
Change-Id: I6564cf636025862c14f0f64a81b1714c2f33ddf1
  • Loading branch information
yaraki committed Aug 10, 2016
1 parent 64216db commit 88c1eca
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.runner.RunWith;

import android.os.Bundle;
import android.os.Parcel;
import android.support.test.rule.UiThreadTestRule;
import android.support.test.runner.AndroidJUnit4;

Expand All @@ -32,24 +33,22 @@
@RunWith(AndroidJUnit4.class)
public class AspectRatioInstrumentationTest {

public UiThreadTestRule rule;

public AspectRatioInstrumentationTest() {
rule = new UiThreadTestRule();
}

@Test
public void testParcel() {
final String key = "key";
AspectRatio ratio = AspectRatio.of(4, 3);
Bundle b = new Bundle();
b.putParcelable(key, ratio);
AspectRatio result = b.getParcelable(key);
assertNotNull(result);
assertThat(result.getX(), is(4));
assertThat(result.getY(), is(3));
// As the first instance is alive, the parceled result should still be the same instance
assertThat(result, is(sameInstance(ratio)));
final AspectRatio original = AspectRatio.of(4, 3);
final Parcel parcel = Parcel.obtain();
try {
parcel.writeParcelable(original, 0);
parcel.setDataPosition(0);
final AspectRatio restored = parcel.readParcelable(getClass().getClassLoader());
assertNotNull(restored);
assertThat(restored.getX(), is(4));
assertThat(restored.getY(), is(3));
// As the first instance is alive, the parceled result should still be the same instance
assertThat(restored, is(sameInstance(original)));
} finally {
parcel.recycle();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void onDisplayOrientationChanged(int displayOrientation) {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mDisplayOrientationDetector.enable(getDisplay());
mDisplayOrientationDetector.enable(ViewCompat2.getDisplay(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2016 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.google.android.cameraview;

import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.hardware.display.DisplayManagerCompat;
import android.support.v4.view.ViewCompat;
import android.view.Display;
import android.view.View;


/**
* Some more addition to {@link android.support.v4.view.ViewCompat}.
*/
class ViewCompat2 {

private ViewCompat2() {
}

/**
* Gets the logical display to which the view's window has been attached.
*
* @param view The view.
* @return The logical display, or null if the view is not currently attached to a window.
*/
public static Display getDisplay(@NonNull View view) {
if (Build.VERSION.SDK_INT >= 17) {
return view.getDisplay();
}
return ViewCompat.isAttachedToWindow(view) ?
DisplayManagerCompat.getInstance(view.getContext())
.getDisplay(Display.DEFAULT_DISPLAY) : null;
}

}

0 comments on commit 88c1eca

Please sign in to comment.