Skip to content

Commit 88242ab

Browse files
committed
Backup point -- Reduced speed fling works, need better logic in the prefetch updater thread (forthcoming)
1 parent c38eae7 commit 88242ab

14 files changed

Lines changed: 61 additions & 150 deletions

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/DisplayFragments.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ public void setCwdFolderContext(DisplayTypes.DirectoryResultContext nextCwdCtx)
8686
public List<String> fileItemBasePathsList = new ArrayList<String>();
8787
public Stack<DisplayTypes.DirectoryResultContext> pathHistoryStack;
8888

89-
public static final int SCROLL_QUEUE_BUFFER_SIZE = 0;
90-
public static final int DEFAULT_VIEWPORT_FILE_ITEMS_COUNT = 15 + SCROLL_QUEUE_BUFFER_SIZE; // set large enough to overfill the window on first load
89+
public static final int DEFAULT_VIEWPORT_FILE_ITEMS_COUNT = 28; // set large enough to overfill the window on first load
9190
private int viewportMaxFileItemsCount = DEFAULT_VIEWPORT_FILE_ITEMS_COUNT;
9291
public int fileItemDisplayHeight = 0;
9392

@@ -106,9 +105,9 @@ public void resetViewportMaxFilesCount(View parentViewContainer) {
106105
if(fileItemDisplayHeight == 0) {
107106
return;
108107
}
109-
setViewportMaxFilesCount(SCROLL_QUEUE_BUFFER_SIZE + (int) Math.floor((double) viewportDisplayHeight / fileItemDisplayHeight));
110-
Log.i(LOGTAG, String.format("DELAYED RESPONSE: VP Height = %d, FItemDisp Height = %d ====> %d (with +%d buffer extra)",
111-
viewportDisplayHeight, fileItemDisplayHeight, getViewportMaxFilesCount(), SCROLL_QUEUE_BUFFER_SIZE));
108+
setViewportMaxFilesCount((int) Math.floor((double) viewportDisplayHeight / fileItemDisplayHeight));
109+
Log.i(LOGTAG, String.format("DELAYED RESPONSE: VP Height = %d, FItemDisp Height = %d ====> %d",
110+
viewportDisplayHeight, fileItemDisplayHeight, getViewportMaxFilesCount()));
112111
viewportCapacityMesaured = true;
113112
}
114113
}

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/FileChooserActivity.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ public void onCreate(Bundle lastSettingsBundle) {
107107
getDisplayFragmentsInstance().allowSelectFolders = fpConfig.allowSelectFolderItems();
108108

109109
prefetchFilesUpdaterInst = new PrefetchFilesUpdater();
110-
Handler startPrefetchFilesThreadHandler = new Handler();
111-
Runnable startPrefetchFilesThreadRunner = new Runnable() {
112-
@Override
113-
public void run() {
114-
FileChooserActivity.getInstance().startPrefetchFileUpdatesThread();
115-
}
116-
};
117-
startPrefetchFilesThreadHandler.postDelayed(startPrefetchFilesThreadRunner, 200);
118110

119111
long idleTimeout = fpConfig.getIdleTimeout();
120112
if(idleTimeout != FileChooserBuilder.NO_ABORT_TIMEOUT) {
@@ -134,8 +126,8 @@ private void configureInitialMainLayout(FileChooserBuilder fpConfig) {
134126

135127
/* Setup the toolbar first: */
136128
Toolbar actionBar = (Toolbar) findViewById(R.id.mainLayoutToolbarActionBar);
137-
actionBar.setTitle(String.format(Locale.getDefault(), " %s (v%s)", getString(R.string.libraryName), String.valueOf(BuildConfig.VERSION_NAME)));
138-
actionBar.setSubtitle(String.format(Locale.getDefault(), "⇤%s⇥", getString(R.string.filePickerTitleText)));
129+
actionBar.setTitle(String.format(Locale.getDefault(), " %s (v%s)", getString(R.string.libraryName), String.valueOf(BuildConfig.VERSION_NAME)));
130+
actionBar.setSubtitle(String.format(Locale.getDefault(), " ⇤%s⇥", getString(R.string.filePickerTitleText)));
139131
actionBar.setTitleTextColor(getColor(R.color.colorMainToolbarForegroundText));
140132
actionBar.setSubtitleTextColor(getColor(R.color.colorMainToolbarForegroundText));
141133
actionBar.setTitleMargin(10, 3, 5, 3);
@@ -175,7 +167,7 @@ public void onClick(View btnView) {
175167
}
176168
};
177169
dirNavBtn.setOnClickListener(stockDirNavBtnClickHandler);
178-
dirNavBtn.setBackgroundColor(DisplayUtils.getColorVariantFromTheme(R.attr.__colorAccent));
170+
dirNavBtn.setBackgroundColor(DisplayUtils.getColorVariantFromTheme(R.attr.colorToolbarNav));
179171
dirNavBtn.setImageDrawable(DisplayUtils.resolveDrawableFromAttribute(defaultDirNavFolders.get(folderIdx).getFolderIconResId()));
180172
fileDirsNavButtonsContainer.addView(dirNavBtn);
181173
}

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/FileChooserRecyclerView.java

Lines changed: 10 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public void setupRecyclerViewLayout() {
7878
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
7979
@Override
8080
public void onGlobalLayout() {
81+
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
8182
DisplayFragments displayFragmentsCtx = DisplayFragments.getInstance();
8283
if(!displayFragmentsCtx.viewportCapacityMesaured && recyclerView.getLayoutManager().getChildCount() != 0) {
8384
displayFragmentsCtx.fileItemDisplayHeight = recyclerView.getLayoutManager().getChildAt(0).getMeasuredHeight();
@@ -86,39 +87,24 @@ public void onGlobalLayout() {
8687
recyclerView.smoothScrollToPosition(0);
8788
}
8889
}
89-
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
90+
FileChooserActivity.getInstance().startPrefetchFileUpdatesThread();
9091
}
9192
});
9293

9394
}
9495

95-
// ??? TODO: ???
96-
/*
96+
// We want it to move when flung and be responsive, but keep a constant rate of movement:
97+
public static final float SCROLLER_MILLISECONDS_PER_INCH = 24.0f; // larger values slow it down
98+
9799
@Override
98100
public boolean fling(int velocityX, int velocityY) {
99-
final LinearLayoutManager rvLayoutManager = (LinearLayoutManager) getLayoutManager();
100-
if (rvLayoutManager != null && rvLayoutManager instanceof FileChooserRecyclerView.LayoutManager) {
101-
super.smoothScrollToPosition(((FileChooserRecyclerView.LayoutManager) getLayoutManager()).getPositionForVelocity(velocityX, velocityY));
102-
return true;
103-
}
104-
return super.fling(velocityX, velocityY);
101+
float slowDownBy = calculateSpeedPerPixel(FileChooserActivity.getInstance().getResources().getDisplayMetrics());
102+
return super.fling((int) (velocityX * slowDownBy), (int) (velocityY * slowDownBy));
105103
}
106-
*/
107104

108-
// ??? TODO: ???
109-
/*
110-
@Override
111-
public boolean onTouchEvent(MotionEvent mevent) {
112-
final boolean returnStatus = super.onTouchEvent(mevent);
113-
final FileChooserRecyclerView.LayoutManager rvLayoutManager = (FileChooserRecyclerView.LayoutManager) getLayoutManager();
114-
if (rvLayoutManager instanceof FileChooserRecyclerView.LayoutManager && getScrollState() == SCROLL_STATE_IDLE &&
115-
(mevent.getAction() == MotionEvent.ACTION_UP || mevent.getAction() == MotionEvent.ACTION_CANCEL)) {
116-
//smoothScrollToPosition(((FileChooserRecyclerView.LayoutManager) rvLayoutManager).getScrollPositionToFixSnapState());
117-
smoothScrollToPosition(((FileChooserRecyclerView.LayoutManager) rvLayoutManager).findFirstVisibleItemPosition());
118-
}
119-
return returnStatus;
105+
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
106+
return SCROLLER_MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
120107
}
121-
*/
122108

123109
public interface RecyclerViewSlidingContextWindow {
124110

@@ -177,95 +163,18 @@ public void restoreDefaultMode() {
177163
setStackFromEnd(true);
178164
}
179165

180-
public int getPositionForVelocity(int velocityX, int velocityY) {
181-
if (getChildCount() == 0) {
182-
return 0;
183-
}
184-
if (getOrientation() == HORIZONTAL) {
185-
return getPositionForVelocity(
186-
velocityX,
187-
getChildAt(0).getLeft(),
188-
getChildAt(0).getWidth(),
189-
getPosition(getChildAt(0))
190-
);
191-
}
192-
else if (getOrientation() == VERTICAL) {
193-
return getPositionForVelocity(
194-
velocityY,
195-
getChildAt(0).getTop(),
196-
getChildAt(0).getHeight(),
197-
getPosition(getChildAt(0))
198-
);
199-
}
200-
else {
201-
return 0;
202-
}
203-
}
204-
205-
// We want it to move when flung and be responsive, but keep a constant rate of movement:
206-
public static final float SCROLLER_MILLISECONDS_PER_INCH = 45f; // larger values slow it down
207-
208-
private int getPositionForVelocity(int velocity, int scrollPos, int childSize, int curPos) {
209-
final double distDelta = ViewConfiguration.getScrollFriction() * velocity * SCROLLER_MILLISECONDS_PER_INCH;
210-
final double nextScrollPos = scrollPos + (velocity > 0 ? distDelta : -distDelta);
211-
if (velocity < 0) {
212-
return (int) Math.max(0, curPos + nextScrollPos / childSize);
213-
} else {
214-
return (int) (curPos + (nextScrollPos / childSize) + getNextPositionOffset());
215-
}
216-
}
217-
218-
/*@Override
166+
@Override
219167
public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) {
220-
221168
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
222-
223-
private float distanceInPixels = 250;
224-
private float scrollDuration = 1.65f;
225-
226-
protected int getHorizontalSnapPreference() {
227-
return SNAP_TO_START;
228-
}
229-
230-
protected int getVerticalSnapPreference() {
231-
// This will scroll at the topmost position (which is the behavior we want):
232-
return SNAP_TO_START;
233-
}
234-
235169
@Override
236170
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
237171
return SCROLLER_MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
238172
}
239-
240-
//@Override
241-
//protected int calculateTimeForScrolling(int deltaX) {
242-
// float alpha = (float) deltaX / distanceInPixels;
243-
// return (int) (scrollDuration * alpha);
244-
//}
245-
246173
};
247174
linearSmoothScroller.setTargetPosition(position);
248175
startSmoothScroll(linearSmoothScroller);
249-
250176
}
251177

252-
public int getScrollPositionToFixSnapState() {
253-
if (getChildCount() == 0) {
254-
return 0;
255-
}
256-
final View child = getChildAt(0);
257-
final int childPosIndex = getPosition(child);
258-
if (getOrientation() == HORIZONTAL && Math.abs(child.getLeft()) > child.getMeasuredWidth() / 2) {
259-
// Scrolled first view is more than halfway offscreen
260-
return childPosIndex + 1;
261-
} else if (getOrientation() == VERTICAL && Math.abs(child.getTop()) > child.getMeasuredWidth() / 2) {
262-
// Scrolled first view is more than halfway offscreen
263-
return childPosIndex + 1;
264-
}
265-
// Keep it where it is located for now:
266-
return childPosIndex;
267-
}*/
268-
269178
}
270179

271180
public static class CustomDividerItemDecoration extends RecyclerView.ItemDecoration {

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/PrefetchFilesUpdater.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void run() {
186186
private static final long THREAD_PAUSE_TIMEOUT = 50; // milliseconds
187187

188188
@Override
189-
public void run() {
189+
public synchronized void run() {
190190

191191
while(true) {
192192

@@ -195,7 +195,7 @@ public void run() {
195195
getLayoutFirstVisibleItemIndex(), getLayoutLastVisibleItemIndex(),
196196
getActiveCountToBalanceTop(), getActiveCountToBalanceBottom(),
197197
getActiveLayoutItemsCount(), getActiveFolderContentsSize()));
198-
// TODO: Need to fix this ???
198+
// TODO: Need to fix these references in case are scrolling ???
199199

200200
// TODO: Check these indices again ...
201201
/*int itemsCountToAppend = getActiveCountToBalanceBottom();
@@ -220,9 +220,9 @@ public void run() {
220220
);
221221
Log.i(LOGTAG, String.format(Locale.getDefault(), "POSTING update to RecyclerView: APPEND #%d data items to BOTTOM", itemsCountToAppend));
222222
postUpdateNotifyToRecyclerView(updateDataBlock, displayFragmentsCtx.getMainRecyclerView());
223-
}
223+
}*/
224224

225-
itemsCountToAppend = getActiveCountToBalanceTop();
225+
/*itemsCountToAppend = getActiveCountToBalanceTop();
226226
if(itemsCountToAppend > 0) { // Prepend at top, trim from bottom:
227227
int startQueryIndex = Math.min(0, getLayoutFirstVisibleItemIndex() + 1 - itemsCountToAppend);
228228
int endQueryIndex = Math.min(getActiveLayoutItemsCount() - 1, startQueryIndex + itemsCountToAppend - 1);
@@ -285,8 +285,8 @@ public int getActiveTopBufferSize() {
285285
return getLayoutFirstVisibleItemIndex() + 1;
286286
}
287287

288-
public int getActiveCountToBalanceBottom() { // ??? TODO ???
289-
if(getActiveFolderContentsSize() >= getActiveLayoutItemsCount()) {
288+
public int getActiveCountToBalanceBottom() {
289+
if(getActiveFolderContentsSize() <= getActiveLayoutItemsCount()) {
290290
return 0;
291291
}
292292
else if(getActiveFolderContentsSize() - getLayoutLastVisibleItemIndex() - 1 < BalancedBufferSize) {
-24 Bytes
Loading
Binary file not shown.
Binary file not shown.

AndroidFilePickerLightLibrary/src/main/res/layout/main_picker_activity_base_layout.xml

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<View
4949
android:layout_width="match_parent"
5050
android:layout_height="5dp"
51-
android:background="?__colorPrimaryVeryDark" />
51+
android:background="?colorToolbarDivider" />
5252

5353
<LinearLayout
5454
android:layout_width="fill_parent"
@@ -58,7 +58,7 @@
5858
android:padding="0dp"
5959
android:layout_gravity="right|center_vertical"
6060
android:gravity="right|center_vertical"
61-
android:background="?__colorAccent"
61+
android:background="?colorToolbarNav"
6262
android:orientation="vertical"
6363
android:clickable="true"
6464
>
@@ -71,7 +71,7 @@
7171
android:layout_marginBottom="1dp"
7272
android:layout_marginRight="8dp"
7373
android:layout_marginLeft="8dp"
74-
android:paddingLeft="15dp"
74+
android:paddingLeft="6dp"
7575
android:paddingRight="15dp"
7676
android:layout_gravity="left|center_vertical"
7777
android:gravity="left|center_vertical"
@@ -102,7 +102,7 @@
102102
<View
103103
android:layout_width="match_parent"
104104
android:layout_height="5dp"
105-
android:background="?__colorPrimaryVeryDark" />
105+
android:background="?colorToolbarDivider" />
106106

107107
<LinearLayout
108108
android:id="@+id/mainDirPrevPathsNavContainer"
@@ -123,23 +123,23 @@
123123
android:layout_height="wrap_content"
124124
android:layout_gravity="left|center_vertical"
125125
android:layout_margin="2dp"
126-
android:paddingLeft="18dp"
126+
android:paddingLeft="6dp"
127+
android:paddingRight="6dp"
127128
android:background="@android:color/transparent"
128129
android:src="@drawable/nav_back_button_icon32"
129130
/>
130131

131-
<ImageView
132-
android:layout_width="wrap_content"
133-
android:layout_height="wrap_content"
134-
android:padding="3dp"
135-
android:layout_marginLeft="12dp"
136-
android:src="@drawable/nav_dirs_path_dotdotdot_icon48" />
137-
138-
<ImageView
132+
<TextView
139133
android:layout_width="wrap_content"
140134
android:layout_height="wrap_content"
141-
android:padding="2dp"
142-
android:src="@drawable/nav_dirs_path_separator_icon48" />
135+
android:gravity="right|center_vertical"
136+
android:layout_gravity="right|center_vertical"
137+
android:text=" {...} / "
138+
android:textColor="?__colorPrimaryDark"
139+
android:textSize="14sp"
140+
android:textStyle="normal|bold"
141+
android:typeface="serif"
142+
/>
143143

144144
<TextView
145145
android:id="@+id/mainDirNavBackTwoPathDisplayText"
@@ -149,16 +149,22 @@
149149
android:layout_gravity="right|center_vertical"
150150
android:text="---"
151151
android:textColor="?__colorPrimaryDark"
152-
android:textSize="11sp"
152+
android:textSize="14sp"
153153
android:textStyle="normal|bold"
154154
android:typeface="serif"
155155
/>
156156

157-
<ImageView
157+
<TextView
158158
android:layout_width="wrap_content"
159159
android:layout_height="wrap_content"
160-
android:padding="2dp"
161-
android:src="@drawable/nav_dirs_path_separator_icon48" />
160+
android:gravity="right|center_vertical"
161+
android:layout_gravity="right|center_vertical"
162+
android:text=" / "
163+
android:textColor="?__colorPrimaryDark"
164+
android:textSize="14sp"
165+
android:textStyle="normal|bold"
166+
android:typeface="serif"
167+
/>
162168

163169
<TextView
164170
android:id="@+id/mainDirNavBackOnePathDisplayText"
@@ -168,7 +174,7 @@
168174
android:layout_gravity="right|center_vertical"
169175
android:text="---"
170176
android:textColor="?__colorPrimaryDark"
171-
android:textSize="11sp"
177+
android:textSize="14sp"
172178
android:textStyle="normal|bold"
173179
android:typeface="serif"
174180
/>
@@ -178,7 +184,7 @@
178184
<View
179185
android:layout_width="match_parent"
180186
android:layout_height="5dp"
181-
android:background="?__colorPrimaryVeryDark" />
187+
android:background="?colorToolbarDivider" />
182188

183189
<LinearLayout
184190
android:id="@+id/mainRecyclerViewContainer"
@@ -213,14 +219,13 @@
213219
android:overScrollMode="never"
214220
android:scrollbarSize="30dp"
215221
/>
216-
<!--android:clickable="true"-->
217222

218223
</LinearLayout>
219224

220225
<View
221226
android:layout_width="match_parent"
222227
android:layout_height="5dp"
223-
android:background="?__colorPrimaryVeryDark" />
228+
android:background="?colorToolbarDivider" />
224229

225230
<LinearLayout
226231
android:layout_width="fill_parent"

AndroidFilePickerLightLibrary/src/main/res/values/attr.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<attr name="mainToolbarBackgroundColor3" format="reference|color" />
3030
<attr name="mainToolbarBackgroundColor4" format="reference|color" />
3131
<attr name="mainToolbarForegroundTextColor" format="reference|color" />
32+
<attr name="colorToolbarDivider" format="reference|color" />
33+
<attr name="colorToolbarNav" format="reference|color" />
3234
<attr name="__colorPrimary" format="reference|color" />
3335
<attr name="__colorPrimaryDark" format="reference|color" />
3436
<attr name="__colorPrimaryVeryDark" format="reference|color" />

0 commit comments

Comments
 (0)