Skip to content

Commit 516228b

Browse files
Auto-update
1 parent 595e178 commit 516228b

31 files changed

+197
-85
lines changed

PdfRendererBasicSample/build.gradle Application/build.gradle

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
buildscript {
52
repositories {
63
mavenCentral()
@@ -11,13 +8,14 @@ buildscript {
118
}
129
}
1310

14-
apply plugin: 'android'
11+
apply plugin: 'com.android.application'
1512

1613

1714
dependencies {
1815

19-
compile "com.android.support:support-v4:20.+"
20-
compile "com.android.support:support-v13:20.+"
16+
compile "com.android.support:support-v4:21.+"
17+
compile "com.android.support:support-v13:21.+"
18+
compile "com.android.support:cardview-v7:21.+"
2119

2220
}
2321

@@ -30,9 +28,13 @@ List<String> dirs = [
3028
'template'] // boilerplate code that is generated by the sample template process
3129

3230
android {
33-
compileSdkVersion "android-L"
31+
compileSdkVersion 21
32+
buildToolsVersion "21.0.0"
3433

35-
buildToolsVersion "20.0.0"
34+
defaultConfig {
35+
minSdkVersion 21
36+
targetSdkVersion 21
37+
}
3638

3739
sourceSets {
3840
main {

PdfRendererBasicSample/src/main/AndroidManifest.xml Application/src/main/AndroidManifest.xml

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
android:versionCode="1"
2121
android:versionName="1.0">
2222

23-
<uses-sdk android:minSdkVersion="L" android:targetSdkVersion="L" />
24-
2523
<application android:allowBackup="true"
2624
android:label="@string/app_name"
2725
android:icon="@drawable/ic_launcher"

PdfRendererBasicSample/src/main/java/com/example/android/pdfrendererbasic/MainActivity.java Application/src/main/java/com/example/android/pdfrendererbasic/MainActivity.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424

2525
public class MainActivity extends Activity {
2626

27+
public static final String FRAGMENT_PDF_RENDERER_BASIC = "pdf_renderer_basic";
28+
2729
@Override
2830
protected void onCreate(Bundle savedInstanceState) {
2931
super.onCreate(savedInstanceState);
3032
setContentView(R.layout.activity_main_real);
3133
if (savedInstanceState == null) {
3234
getFragmentManager().beginTransaction()
33-
.add(R.id.container, new PdfRendererBasicFragment())
35+
.add(R.id.container, new PdfRendererBasicFragment(),
36+
FRAGMENT_PDF_RENDERER_BASIC)
3437
.commit();
3538
}
3639
}

PdfRendererBasicSample/src/main/java/com/example/android/pdfrendererbasic/PdfRendererBasicFragment.java Application/src/main/java/com/example/android/pdfrendererbasic/PdfRendererBasicFragment.java

+9
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ private void updateUi() {
193193
getActivity().setTitle(getString(R.string.app_name_with_index, index + 1, pageCount));
194194
}
195195

196+
/**
197+
* Gets the number of pages in the PDF. This method is marked as public for testing.
198+
*
199+
* @return The number of pages.
200+
*/
201+
public int getPageCount() {
202+
return mPdfRenderer.getPageCount();
203+
}
204+
196205
@Override
197206
public void onClick(View view) {
198207
switch (view.getId()) {

PdfRendererBasicSample/src/main/res/values/base-strings.xml Application/src/main/res/values/base-strings.xml

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
18-
19-
2017
<resources>
2118
<string name="app_name">PdfRendererBasic</string>
2219
<string name="intro_message">

Application/tests/AndroidManifest.xml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2014 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
18+
<manifest
19+
package="com.example.android.pdfrendererbasic.tests"
20+
xmlns:android="http://schemas.android.com/apk/res/android"
21+
android:versionCode="1"
22+
android:versionName="1.0">
23+
24+
<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->
25+
26+
<!-- We add an application tag here just so that we can indicate that
27+
this package needs to link against the android.test library,
28+
which is needed when building test cases. -->
29+
<application>
30+
<uses-library android:name="android.test.runner"/>
31+
</application>
32+
33+
<!--
34+
Specifies the instrumentation test runner used to run the tests.
35+
-->
36+
<instrumentation
37+
android:name="android.test.InstrumentationTestRunner"
38+
android:label="Tests for com.example.android.pdfrendererbasic"
39+
android:targetPackage="com.example.android.pdfrendererbasic"/>
40+
41+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.pdfrendererbasic.tests;
18+
19+
import android.content.pm.ActivityInfo;
20+
import android.test.ActivityInstrumentationTestCase2;
21+
import android.test.TouchUtils;
22+
import android.test.suitebuilder.annotation.LargeTest;
23+
import android.view.View;
24+
import android.widget.Button;
25+
26+
import com.example.android.pdfrendererbasic.MainActivity;
27+
import com.example.android.pdfrendererbasic.PdfRendererBasicFragment;
28+
import com.example.android.pdfrendererbasic.R;
29+
30+
/**
31+
* Tests for PdfRendererBasic sample.
32+
*/
33+
public class PdfRendererBasicFragmentTests extends ActivityInstrumentationTestCase2<MainActivity> {
34+
35+
private MainActivity mActivity;
36+
private PdfRendererBasicFragment mFragment;
37+
38+
private Button mButtonPrevious;
39+
private Button mButtonNext;
40+
41+
public PdfRendererBasicFragmentTests() {
42+
super(MainActivity.class);
43+
}
44+
45+
@Override
46+
protected void setUp() throws Exception {
47+
super.setUp();
48+
mActivity = getActivity();
49+
mFragment = (PdfRendererBasicFragment) mActivity.getFragmentManager()
50+
.findFragmentByTag(MainActivity.FRAGMENT_PDF_RENDERER_BASIC);
51+
}
52+
53+
@LargeTest
54+
public void testActivityTitle() {
55+
// The title of the activity should be "PdfRendererBasic (1/10)" at first
56+
String expectedActivityTitle = mActivity.getString(R.string.app_name_with_index, 1,
57+
mFragment.getPageCount());
58+
assertEquals(expectedActivityTitle, mActivity.getTitle());
59+
}
60+
61+
@LargeTest
62+
public void testButtons_previousDisabledAtFirst() {
63+
setUpButtons();
64+
// Check that the previous button is disabled at first
65+
assertFalse(mButtonPrevious.isEnabled());
66+
// The next button should be enabled
67+
assertTrue(mButtonNext.isEnabled());
68+
}
69+
70+
@LargeTest
71+
public void testButtons_bothEnabledInMiddle() {
72+
setUpButtons();
73+
turnPages(1);
74+
// Two buttons should be both enabled
75+
assertTrue(mButtonPrevious.isEnabled());
76+
assertTrue(mButtonNext.isEnabled());
77+
}
78+
79+
@LargeTest
80+
public void testButtons_nextDisabledLastPage() {
81+
setUpButtons();
82+
int pageCount = mFragment.getPageCount();
83+
// Click till it reaches the last page
84+
turnPages(pageCount - 1);
85+
// Check the page count
86+
String expectedActivityTitle = mActivity.getString(R.string.app_name_with_index,
87+
pageCount, pageCount);
88+
assertEquals(expectedActivityTitle, mActivity.getTitle());
89+
// The previous button should be enabled
90+
assertTrue(mButtonPrevious.isEnabled());
91+
// Check that the next button is disabled
92+
assertFalse(mButtonNext.isEnabled());
93+
}
94+
95+
@LargeTest
96+
public void testOrientationChangePreserveState() {
97+
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
98+
setUpButtons();
99+
turnPages(1);
100+
int pageCount = mFragment.getPageCount();
101+
String expectedActivityTitle = mActivity.getString(R.string.app_name_with_index,
102+
2, pageCount);
103+
assertEquals(expectedActivityTitle, mActivity.getTitle());
104+
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
105+
// Check that the title is the same after orientation change
106+
assertEquals(expectedActivityTitle, mActivity.getTitle());
107+
}
108+
109+
/**
110+
* Prepares references to the buttons "Previous" and "Next".
111+
*/
112+
private void setUpButtons() {
113+
View view = mFragment.getView();
114+
assertNotNull(view);
115+
mButtonPrevious = (Button) view.findViewById(R.id.previous);
116+
assertNotNull(mButtonPrevious);
117+
mButtonNext = (Button) view.findViewById(R.id.next);
118+
assertNotNull(mButtonNext);
119+
}
120+
121+
/**
122+
* Click the "Next" button to turn the pages.
123+
*
124+
* @param count The number of times to turn pages.
125+
*/
126+
private void turnPages(int count) {
127+
for (int i = 0; i < count; ++i) {
128+
TouchUtils.clickView(this, mButtonNext);
129+
}
130+
}
131+
132+
}

README.md

-52
This file was deleted.

packaging.yaml

-15
This file was deleted.

settings.gradle

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
2-
3-
4-
include 'PdfRendererBasicSample'
1+
include 'Application'

0 commit comments

Comments
 (0)