Skip to content

Commit 77e8024

Browse files
author
Iain Connor
committed
Got fixed width optimizations mostly working
1 parent 22eb289 commit 77e8024

File tree

13 files changed

+186
-67
lines changed

13 files changed

+186
-67
lines changed

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 21
5-
buildToolsVersion "21.1.2"
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.0"
66

77
defaultConfig {
88
applicationId "com.tippingcanoe.dewey.app"
99
minSdkVersion 10
10-
targetSdkVersion 21
10+
targetSdkVersion 23
1111
versionCode 1
1212
versionName "1.0"
1313
}
@@ -21,6 +21,6 @@ android {
2121

2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
compile 'com.android.support:appcompat-v7:21.0.3'
24+
compile 'com.android.support:appcompat-v7:23.0.1'
2525
compile project(':library')
2626
}

app/src/androidTest/java/com/tippingcanoe/dewey/app/ApplicationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
1010
public ApplicationTest () {
1111
super(Application.class);
1212
}
13-
}
13+
}

app/src/main/java/com/tippingcanoe/dewey/app/DemoAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.tippingcanoe.dewey.app;
22

3+
import android.graphics.Color;
34
import android.support.v7.widget.RecyclerView;
45
import android.view.LayoutInflater;
56
import android.view.View;
@@ -31,7 +32,7 @@ public void onBindViewHolder ( DeweyViewHolder holder, int position ) {
3132

3233
@Override
3334
public int getItemCount () {
34-
return sentances.size();
35+
return 50;//return sentances.size();
3536
}
3637

3738
protected List<String> getRandomSentances () {
@@ -42,7 +43,7 @@ protected List<String> getRandomSentances () {
4243
final int LOW = 1;
4344
final int HIGH = 1;
4445

45-
for (int i = 0; i <= 30; i++) {
46+
for (int i = 0; i <= getItemCount(); i++) {
4647
String sentance = "";
4748

4849
for (int j = 0; j <= (HIGH - LOW == 0 ? 0 : random.nextInt(HIGH - LOW) + LOW); j++) {

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
android:layout_width="wrap_content"
1515
android:layout_height="wrap_content"
1616
android:background="@color/material_deep_teal_200"
17-
custom:stripColor="@color/accent_material_light" />
17+
custom:stripColor="@color/accent_material_light"
18+
custom:uniformCells="true" />
1819

1920
<LinearLayout
2021
android:layout_width="match_parent"

app/src/main/res/layout/dewey_cell.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<TextView
33
android:id="@+id/dewey_cell_label"
44
xmlns:android="http://schemas.android.com/apk/res/android"
5-
android:layout_width="wrap_content"
5+
android:layout_width="40dp"
66
android:layout_height="wrap_content"
77
android:gravity="center"
8-
android:padding="10dp" />
8+
android:padding="10dp"
9+
android:ellipsize="end"/>

library/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 21
5-
buildToolsVersion "21.1.2"
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.0"
66

77
defaultConfig {
88
minSdkVersion 10
9-
targetSdkVersion 21
9+
targetSdkVersion 23
1010
versionCode 1
1111
versionName "1.0"
1212
}
@@ -21,6 +21,6 @@ android {
2121
dependencies {
2222
compile fileTree(dir: 'libs', include: ['*.jar'])
2323

24-
compile 'com.android.support:appcompat-v7:21.0.+'
25-
compile 'com.android.support:recyclerview-v7:21.0.+'
24+
compile 'com.android.support:appcompat-v7:23.0.1'
25+
compile 'com.android.support:recyclerview-v7:23.0.1'
2626
}

library/library.iml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Dewey" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="dewey" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -12,10 +12,12 @@
1212
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
1313
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
1414
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
15-
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
1615
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
1716
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
18-
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
17+
<afterSyncTasks>
18+
<task>generateDebugSources</task>
19+
<task>generateDebugTestSources</task>
20+
</afterSyncTasks>
1921
<option name="ALLOW_USER_CONFIGURATION" value="false" />
2022
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
2123
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@@ -25,7 +27,7 @@
2527
</configuration>
2628
</facet>
2729
</component>
28-
<component name="NewModuleRootManager" inherit-compiler-output="false">
30+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
2931
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
3032
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
3133
<exclude-output />
@@ -85,11 +87,11 @@
8587
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
8688
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
8789
</content>
88-
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
90+
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
8991
<orderEntry type="sourceFolder" forTests="false" />
90-
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
91-
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
92-
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
93-
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
92+
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
93+
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
94+
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
95+
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
9496
</component>
9597
</module>

library/src/androidTest/java/com/tippingcanoe/dewey/ApplicationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
1010
public ApplicationTest () {
1111
super(Application.class);
1212
}
13-
}
13+
}

library/src/main/java/com/tippingcanoe/dewey/Dewey.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.content.res.TypedArray;
55
import android.graphics.Color;
6+
import android.support.annotation.ColorInt;
67
import android.support.annotation.ColorRes;
78
import android.support.annotation.DimenRes;
89
import android.support.annotation.Nullable;
@@ -54,10 +55,7 @@ public Dewey ( Context context, AttributeSet attrs, int defStyle ) {
5455
}
5556

5657
protected void setup ( Context context, @Nullable AttributeSet attrs ) {
57-
layoutManager = new DeweyLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
58-
setLayoutManager(layoutManager);
59-
setHasFixedSize(true);
60-
setHorizontalScrollBarEnabled(false);
58+
boolean uniformCells = false;
6159

6260
if (attrs != null) {
6361
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Dewey, 0, 0);
@@ -68,20 +66,30 @@ protected void setup ( Context context, @Nullable AttributeSet attrs ) {
6866
stripHeight = typedArray.getDimensionPixelSize(R.styleable.Dewey_stripHeight, stripHeight);
6967
stripColor = typedArray.getColor(R.styleable.Dewey_stripColor, stripColor);
7068
animationDurationMs = typedArray.getInteger(R.styleable.Dewey_animationDurationMs, animationDurationMs);
69+
uniformCells = typedArray.getBoolean(R.styleable.Dewey_uniformCells, uniformCells);
7170
} finally {
7271
typedArray.recycle();
7372
}
7473
}
7574

75+
layoutManager = new DeweyLayoutManager(context, LinearLayoutManager.HORIZONTAL, false, uniformCells);
76+
setLayoutManager(layoutManager);
77+
setHasFixedSize(true);
78+
setHorizontalScrollBarEnabled(false);
79+
7680
setFocusedPosition(0, false);
7781
}
7882

7983
public void setFocusedPosition ( int position, boolean animated ) {
80-
if (onFocusedPositionChangedListener != null) {
84+
setFocusedPosition(position, animated, false);
85+
}
86+
87+
public void setFocusedPosition ( int position, boolean animated, boolean silently ) {
88+
if (!silently && onFocusedPositionChangedListener != null) {
8189
onFocusedPositionChangedListener.onFocusedPositionChanged(focusedPosition, position);
8290
}
8391

84-
boolean requestedPositionIsVisible = position >= getChildPosition(getChildAt(0)) && position <= getChildPosition(getChildAt(getChildCount() - 1));
92+
boolean requestedPositionIsVisible = position >= getChildAdapterPosition(getChildAt(0)) && position <= getChildAdapterPosition(getChildAt(getChildCount() - 1));
8593

8694
// @TODO, enhance this by attempting to center the focused position.
8795
if (requestedPositionIsVisible && animated) {
@@ -120,13 +128,13 @@ public void setOnFocusedPositionChangedListener ( OnFocusedPositionChangedListen
120128
}
121129

122130
public
123-
@ColorRes
131+
@ColorInt
124132
int getCloakColor () {
125133
return cloakColor;
126134
}
127135

128136
public void setCloakColor ( @ColorRes int cloakColor ) {
129-
this.cloakColor = cloakColor;
137+
this.cloakColor = getResources().getColor(cloakColor);
130138

131139
if (deweyDecorator != null) {
132140
deweyDecorator.setupCloak();
@@ -150,15 +158,15 @@ public int getStripHeight () {
150158
}
151159

152160
public void setStripHeight ( @DimenRes int stripHeight ) {
153-
this.stripHeight = stripHeight;
161+
this.stripHeight = getResources().getDimensionPixelSize(stripHeight);
154162
}
155163

156-
public int getStripColor () {
164+
public @ColorInt int getStripColor () {
157165
return stripColor;
158166
}
159167

160168
public void setStripColor ( @ColorRes int stripColor ) {
161-
this.stripColor = stripColor;
169+
this.stripColor = getResources().getColor(stripColor);
162170

163171
if (deweyDecorator != null) {
164172
deweyDecorator.setupStrip();
@@ -189,6 +197,14 @@ public void setCloakCurveInterpolator ( Interpolator cloakCurveInterpolator ) {
189197
this.cloakCurveInterpolator = cloakCurveInterpolator;
190198
}
191199

200+
public boolean areCellsUniform() {
201+
return ((DeweyLayoutManager) getLayoutManager()).areCellsUniform();
202+
}
203+
204+
public void setUniformCells(boolean uniformCells) {
205+
((DeweyLayoutManager) getLayoutManager()).setUniformCells(uniformCells);
206+
}
207+
192208
public static interface OnFocusedPositionChangedListener {
193209
void onFocusedPositionChanged ( int previousFocusedPosition, int newFocusedPosition );
194210
}

0 commit comments

Comments
 (0)