Format code

captchafix
Florens Douwes 11 years ago
parent 4293a41830
commit 30724d2148
  1. 9
      Chan/src/org/floens/chan/chan/ChanUrls.java
  2. 9
      Chan/src/org/floens/chan/core/ChanPreferences.java
  3. 8
      Chan/src/org/floens/chan/core/loader/Loader.java
  4. 2
      Chan/src/org/floens/chan/core/loader/LoaderPool.java
  5. 16
      Chan/src/org/floens/chan/core/manager/BoardManager.java
  6. 65
      Chan/src/org/floens/chan/core/manager/ReplyManager.java
  7. 3
      Chan/src/org/floens/chan/core/manager/ThreadManager.java
  8. 8
      Chan/src/org/floens/chan/core/model/Board.java
  9. 23
      Chan/src/org/floens/chan/core/model/Loadable.java
  10. 7
      Chan/src/org/floens/chan/core/model/Pin.java
  11. 4
      Chan/src/org/floens/chan/core/model/PostLinkable.java
  12. 10
      Chan/src/org/floens/chan/core/net/BoardsRequest.java
  13. 4
      Chan/src/org/floens/chan/core/net/ByteArrayRequest.java
  14. 43
      Chan/src/org/floens/chan/core/net/ChanReaderRequest.java
  15. 4
      Chan/src/org/floens/chan/core/net/GIFRequest.java
  16. 4
      Chan/src/org/floens/chan/core/net/JsonReaderRequest.java
  17. 7
      Chan/src/org/floens/chan/database/DatabaseHelper.java
  18. 7
      Chan/src/org/floens/chan/database/DatabaseManager.java
  19. 14
      Chan/src/org/floens/chan/ui/ScrollerRunnable.java
  20. 119
      Chan/src/org/floens/chan/ui/SwipeDismissListViewTouchListener.java
  21. 28
      Chan/src/org/floens/chan/ui/ViewFlipperAnimations.java
  22. 21
      Chan/src/org/floens/chan/ui/activity/BoardEditor.java
  23. 5
      Chan/src/org/floens/chan/ui/activity/DeveloperActivity.java
  24. 5
      Chan/src/org/floens/chan/ui/activity/ImagePickActivity.java
  25. 2
      Chan/src/org/floens/chan/ui/activity/ReplyActivity.java
  26. 5
      Chan/src/org/floens/chan/ui/adapter/BoardEditAdapter.java
  27. 13
      Chan/src/org/floens/chan/ui/adapter/ImageViewAdapter.java
  28. 9
      Chan/src/org/floens/chan/ui/adapter/PostAdapter.java
  29. 8
      Chan/src/org/floens/chan/ui/fragment/PostRepliesFragment.java
  30. 85
      Chan/src/org/floens/chan/ui/fragment/ReplyFragment.java
  31. 7
      Chan/src/org/floens/chan/ui/fragment/SettingsFragment.java
  32. 12
      Chan/src/org/floens/chan/ui/fragment/ThreadFragment.java
  33. 136
      Chan/src/org/floens/chan/ui/view/DynamicListView.java
  34. 11
      Chan/src/org/floens/chan/ui/view/GIFView.java
  35. 10
      Chan/src/org/floens/chan/ui/view/NetworkPhotoView.java
  36. 7
      Chan/src/org/floens/chan/ui/view/ThreadWatchCounterView.java
  37. 1
      Chan/src/org/floens/chan/utils/IOUtils.java
  38. 1
      Chan/src/org/floens/chan/utils/IconCache.java
  39. 21
      Chan/src/org/floens/chan/utils/ImageDecoder.java
  40. 16
      Chan/src/org/floens/chan/utils/ImageSaver.java
  41. 1
      Chan/src/org/floens/chan/utils/Logger.java
  42. 26
      Chan/src/org/floens/chan/utils/Utils.java

@ -41,12 +41,12 @@ public class ChanUrls {
public static String getPostUrl(String board) {
return "https://sys.4chan.org/" + board + "/post";
// return "http://192.168.6.214/Testing/PostEchoer/post.php";
// return "http://192.168.6.214/Testing/PostEchoer/post.php";
}
public static String getDeleteUrl(String board) {
return "https://sys.4chan.org/" + board + "/imgboard.php";
// return "http://192.168.6.214/Testing/PostEchoer/post.php";
// return "http://192.168.6.214/Testing/PostEchoer/post.php";
}
public static String getBoardUrlDesktop(String board) {
@ -61,8 +61,3 @@ public class ChanUrls {
return "https://boards.4chan.org/" + board + "/catalog";
}
}

@ -33,8 +33,8 @@ public class ChanPreferences {
}
/**
* This also calls updateRunningState on the PinnedService to
* start/stop the service as needed.
* This also calls updateRunningState on the PinnedService to start/stop the
* service as needed.
*
* @param enabled
*/
@ -59,8 +59,3 @@ public class ChanPreferences {
return ChanApplication.getPreferences().getBoolean("preference_autoplay", false);
}
}

@ -85,9 +85,9 @@ public class Loader {
}
/**
* Request more data if the time left is below 0
* If auto load more is disabled, this needs to be called manually.
* Otherwise this is called automatically when the timer hits 0.
* Request more data if the time left is below 0 If auto load more is
* disabled, this needs to be called manually. Otherwise this is called
* automatically when the timer hits 0.
*/
public void loadMoreIfTime() {
if (getTimeUntilLoadMore() < 0L) {
@ -165,6 +165,7 @@ public class Loader {
/**
* Get the time in milliseconds until another loadMore is recommended
*
* @return
*/
public long getTimeUntilLoadMore() {
@ -291,6 +292,7 @@ public class Loader {
public static interface LoaderListener {
public void onData(List<Post> result, boolean append);
public void onError(VolleyError error);
}
}

@ -6,7 +6,7 @@ import java.util.Map;
import org.floens.chan.core.model.Loadable;
public class LoaderPool {
// private static final String TAG = "LoaderPool";
// private static final String TAG = "LoaderPool";
private static LoaderPool instance;

@ -37,6 +37,7 @@ public class BoardManager {
/**
* Avoid having 0 boards, which causes graphical problems
*
* @param list
*/
private ArrayList<Board> getDefaultBoards() {
@ -125,6 +126,7 @@ public class BoardManager {
/**
* Try to add value to the supplied list.
*
* @param list
* @param value
*/
@ -174,7 +176,8 @@ public class BoardManager {
private ArrayList<Board> getBoardListFromDatabase(String key) {
String total = ChanApplication.getPreferences().getString(key, null);
if (total == null) return null;
if (total == null)
return null;
ArrayList<Board> list = new ArrayList<Board>();
@ -184,7 +187,8 @@ public class BoardManager {
String line = scanner.nextLine();
String[] splitted = line.split("\\|");
if (splitted.length < 2) continue;
if (splitted.length < 2)
continue;
Board board = new Board();
board.key = splitted[0];
@ -207,7 +211,8 @@ public class BoardManager {
allBoards = temp;
}
ChanApplication.getVolleyRequestQueue().add(new BoardsRequest(ChanUrls.getBoardsUrl(), new Response.Listener<ArrayList<Board>>() {
ChanApplication.getVolleyRequestQueue().add(
new BoardsRequest(ChanUrls.getBoardsUrl(), new Response.Listener<ArrayList<Board>>() {
@Override
public void onResponse(ArrayList<Board> data) {
storeBoardListInDatabase("allBoards", data);
@ -223,8 +228,3 @@ public class BoardManager {
}));
}
}

@ -59,7 +59,9 @@ public class ReplyManager {
/**
* Set an reply draft.
* @param value the draft to save.
*
* @param value
* the draft to save.
*/
public void setReplyDraft(Reply value) {
draft = value;
@ -67,6 +69,7 @@ public class ReplyManager {
/**
* Gets the saved reply draft.
*
* @return the saved draft or an empty draft.
*/
public Reply getReplyDraft() {
@ -75,7 +78,9 @@ public class ReplyManager {
/**
* Add an quote to the comment field. Looks like >>123456789\n
* @param no the raw no to quote to.
*
* @param no
* the raw no to quote to.
*/
public void quote(int no) {
draft.comment = draft.comment + ">>" + no + "\n";
@ -83,7 +88,9 @@ public class ReplyManager {
/**
* Pick an file. Starts up the ImagePickActivity.
* @param listener FileListener to listen on.
*
* @param listener
* FileListener to listen on.
*/
public void pickFile(FileListener listener) {
fileListener = listener;
@ -103,7 +110,8 @@ public class ReplyManager {
}
/**
* Called from ImagePickActivity. Sends the file to the listening fileListener, and deletes the fileListener.
* Called from ImagePickActivity. Sends the file to the listening
* fileListener, and deletes the fileListener.
*/
public void _onPickedFile(File file) {
if (fileListener != null) {
@ -121,7 +129,9 @@ public class ReplyManager {
/**
* Get the CAPTCHA challenge hash from an JSON response.
* @param total The total response from the server
*
* @param total
* The total response from the server
* @return The pattern, or null when none was found.
*/
public static String getChallenge(String total) {
@ -137,8 +147,12 @@ public class ReplyManager {
/**
* Send an reply off to the server.
* @param reply The reply object with all data needed, like captcha and the file.
* @param listener The listener, after server response.
*
* @param reply
* The reply object with all data needed, like captcha and the
* file.
* @param listener
* The listener, after server response.
*/
public void sendDelete(final SavedReply reply, boolean onlyImageDelete, final DeleteListener listener) {
Logger.i(TAG, "Sending delete request: " + reply.board + ", " + reply.no);
@ -196,8 +210,12 @@ public class ReplyManager {
/**
* Send an reply off to the server.
* @param reply The reply object with all data needed, like captcha and the file.
* @param listener The listener, after server response.
*
* @param reply
* The reply object with all data needed, like captcha and the
* file.
* @param listener
* The listener, after server response.
*/
public void sendReply(final Reply reply, final ReplyListener listener) {
Logger.i(TAG, "Sending reply request: " + reply.board + ", " + reply.resto);
@ -248,8 +266,8 @@ public class ReplyManager {
if (responseString.contains("No file selected")) {
e.isUserError = true;
e.isFileError = true;
} else if (responseString.contains("You forgot to solve the CAPTCHA") ||
responseString.contains("You seem to have mistyped the CAPTCHA")) {
} else if (responseString.contains("You forgot to solve the CAPTCHA")
|| responseString.contains("You seem to have mistyped the CAPTCHA")) {
e.isUserError = true;
e.isCaptchaError = true;
} else if (responseString.toLowerCase(Locale.ENGLISH).contains("post successful")) {
@ -282,11 +300,12 @@ public class ReplyManager {
}
/**
* Async task to send an reply to the server.
* Uses HttpClient. Since Android 4.4 there is an updated version of HttpClient, 4.2, given with Android.
* However, that version causes problems with file uploading. Version 4.3 of HttpClient has been given with a library,
* that has another namespace: ch.boye.httpclientandroidlib
* This lib also has some fixes/improvements of HttpClient for Android.
* Async task to send an reply to the server. Uses HttpClient. Since Android
* 4.4 there is an updated version of HttpClient, 4.2, given with Android.
* However, that version causes problems with file uploading. Version 4.3 of
* HttpClient has been given with a library, that has another namespace:
* ch.boye.httpclientandroidlib This lib also has some fixes/improvements of
* HttpClient for Android.
*/
private void sendHttpPost(final HttpPost post, final HttpPostSendListener listener) {
new Thread(new Runnable() {
@ -328,9 +347,12 @@ public class ReplyManager {
public static abstract class FileListener {
/**
* When a file is picked.
* @param the picked file
*
* @param the
* picked file
*/
public abstract void onFile(File file);
/**
* When the file has started loading.
*/
@ -382,14 +404,9 @@ public class ReplyManager {
public boolean isSuccessful = false;
/**
* Raw html from the response. Used to set html in an WebView to the client, when the error was not
* recognized by Chan.
* Raw html from the response. Used to set html in an WebView to the
* client, when the error was not recognized by Chan.
*/
public String responseData = "";
}
}

@ -277,7 +277,8 @@ public class ThreadManager implements Loader.LoaderListener {
String text = "";
if (post.hasImage) {
text += "File: " + post.filename + "." + post.ext + " \nSize: " + post.imageWidth + "x" + post.imageHeight + "\n\n";
text += "File: " + post.filename + "." + post.ext + " \nSize: " + post.imageWidth + "x" + post.imageHeight
+ "\n\n";
}
text += "Time: " + post.date;

@ -1,9 +1,8 @@
package org.floens.chan.core.model;
/**
* Board key and value.
* key is full name e.g. Literature.
* value is board key e.g. lit.
* Board key and value. key is full name e.g. Literature. value is board key
* e.g. lit.
*/
public class Board {
/**
@ -18,7 +17,8 @@ public class Board {
public boolean workSafe = false;
public boolean finish() {
if (key == null || value == null) return false;
if (key == null || value == null)
return false;
return true;
}

@ -33,20 +33,20 @@ public class Loadable {
public int listViewTop;
/**
* When simple mode is enabled, CPU intensive methods won't get called.
* This is used for the thread watcher.
* When simple mode is enabled, CPU intensive methods won't get called. This
* is used for the thread watcher.
*/
public boolean simpleMode = false;
/**
* Constructs an empty loadable.
* The mode is INVALID.
* Constructs an empty loadable. The mode is INVALID.
*/
public Loadable() {
}
/**
* Quick constructor for a board loadable.
*
* @param board
*/
public Loadable(String board) {
@ -57,6 +57,7 @@ public class Loadable {
/**
* Quick constructor for a thread loadable.
*
* @param board
* @param no
*/
@ -68,6 +69,7 @@ public class Loadable {
/**
* Quick constructor for a thread loadable with an title.
*
* @param board
* @param no
* @param title
@ -84,14 +86,12 @@ public class Loadable {
*/
@Override
public boolean equals(Object object) {
if (!(object instanceof Loadable)) return false;
if (!(object instanceof Loadable))
return false;
Loadable other = (Loadable) object;
return
mode == other.mode &&
board.equals(other.board) &&
no == other.no;
return mode == other.mode && board.equals(other.board) && no == other.no;
}
public boolean isBoardMode() {
@ -166,8 +166,3 @@ public class Loadable {
public static final int CATALOG = 2;
}
}

@ -17,9 +17,9 @@ public class Pin {
// ListView Stuff
/** Header is used to display a static header in the drawer listview. */
public Type type = Type.THREAD;
public static enum Type {
HEADER,
THREAD
HEADER, THREAD
};
// PinnedService stuff
@ -85,6 +85,3 @@ public class Pin {
}
}
}

@ -9,7 +9,9 @@ import android.view.View;
* Anything that links to something in a post uses this entity.
*/
public class PostLinkable extends ClickableSpan {
public static enum Type {QUOTE, LINK};
public static enum Type {
QUOTE, LINK
};
public final Post post;
public final String key;

@ -31,7 +31,7 @@ public class BoardsRequest extends JsonReaderRequest<ArrayList<Board>> {
if (key.equals("boards")) {
reader.beginArray();
while(reader.hasNext()) {
while (reader.hasNext()) {
list.add(readBoardEntry(reader));
}
@ -41,11 +41,11 @@ public class BoardsRequest extends JsonReaderRequest<ArrayList<Board>> {
}
}
reader.endObject();
} catch(IOException e) {
} catch (IOException e) {
e.printStackTrace();
} catch(NumberFormatException e) {
} catch (NumberFormatException e) {
e.printStackTrace();
} catch(IllegalStateException e) {
} catch (IllegalStateException e) {
e.printStackTrace();
}
@ -62,7 +62,7 @@ public class BoardsRequest extends JsonReaderRequest<ArrayList<Board>> {
Board board = new Board();
while(reader.hasNext()) {
while (reader.hasNext()) {
String key = reader.nextName();
if (key.equals("title")) {

@ -7,8 +7,7 @@ import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
/**
* Request a plain byte[]
* Warning: no caching!
* Request a plain byte[] Warning: no caching!
*/
public class ByteArrayRequest extends Request<byte[]> {
protected final Listener<byte[]> listener;
@ -29,4 +28,3 @@ public class ByteArrayRequest extends Request<byte[]> {
return Response.success(response.data, null);
}
}

@ -25,14 +25,19 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
/**
* Creates a ChanReaderRequest with supplied params
* @param mode ThreadManager mode
* @param board board key
* @param no page for board, no for threads
*
* @param mode
* ThreadManager mode
* @param board
* board key
* @param no
* page for board, no for threads
* @param listener
* @param errorListener
* @return New instance of ChanReaderRequest
*/
public static ChanReaderRequest newInstance(Loadable loadable, List<Post> cached, Listener<List<Post>> listener, ErrorListener errorListener) {
public static ChanReaderRequest newInstance(Loadable loadable, List<Post> cached, Listener<List<Post>> listener,
ErrorListener errorListener) {
String url;
if (loadable.isBoardMode()) {
@ -110,13 +115,13 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
}
}
reader.endObject();
} catch(IOException e) {
} catch (IOException e) {
e.printStackTrace();
setError(new ParseError(e));
} catch(NumberFormatException e) {
} catch (NumberFormatException e) {
e.printStackTrace();
setError(new ParseError(e));
} catch(IllegalStateException e) {
} catch (IllegalStateException e) {
e.printStackTrace();
setError(new ParseError(e));
}
@ -142,7 +147,8 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
list.add(readPostObject(reader));
// Only consume one post
while (reader.hasNext()) reader.skipValue();
while (reader.hasNext())
reader.skipValue();
reader.endArray();
} else {
@ -158,13 +164,13 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
}
reader.endObject();
} catch(IOException e) {
} catch (IOException e) {
e.printStackTrace();
setError(new ParseError(e));
} catch(NumberFormatException e) {
} catch (NumberFormatException e) {
e.printStackTrace();
setError(new ParseError(e));
} catch(IllegalStateException e) {
} catch (IllegalStateException e) {
e.printStackTrace();
setError(new ParseError(e));
}
@ -199,13 +205,13 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
}
reader.endArray();
} catch(IOException e) {
} catch (IOException e) {
e.printStackTrace();
setError(new ParseError(e));
} catch(NumberFormatException e) {
} catch (NumberFormatException e) {
e.printStackTrace();
setError(new ParseError(e));
} catch(IllegalStateException e) {
} catch (IllegalStateException e) {
e.printStackTrace();
setError(new ParseError(e));
}
@ -218,7 +224,7 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
post.board = loadable.board;
reader.beginObject();
while(reader.hasNext()) {
while (reader.hasNext()) {
String key = reader.nextName();
if (key.equals("no")) {
@ -270,7 +276,7 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
post.capcode = reader.nextString();
} else {
// Unknown/ignored key
// log("Unknown/ignored key: " + key + ".");
// log("Unknown/ignored key: " + key + ".");
reader.skipValue();
}
}
@ -295,8 +301,3 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
}
}
}

@ -40,7 +40,3 @@ public class GIFRequest extends Request<GIFView> {
}
}
}

@ -68,7 +68,3 @@ public abstract class JsonReaderRequest<T> extends Request<T> {
public abstract T readJson(JsonReader reader);
}

@ -55,7 +55,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
switch(oldVersion) {
switch (oldVersion) {
// Change tables if we make adjustments
}
@ -83,8 +83,3 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
}
}

@ -95,7 +95,7 @@ public class DatabaseManager {
for (Pin pin : pins) {
helper.loadableDao.update(pin.loadable);
}
} catch(SQLException e) {
} catch (SQLException e) {
Logger.e(TAG, "Error updating pins in db", e);
}
}
@ -133,8 +133,3 @@ public class DatabaseManager {
loadSavedReplies();
}
}

@ -26,12 +26,12 @@ public class ScrollerRunnable implements Runnable {
final int firstPos = mList.getFirstVisiblePosition();
final int lastPos = firstPos + mList.getChildCount() - 1;
// int viewTravelCount = 0;
// int viewTravelCount = 0;
if (position <= firstPos) {
// viewTravelCount = firstPos - position + 1;
// viewTravelCount = firstPos - position + 1;
mMode = MOVE_UP_POS;
} else if (position >= lastPos) {
// viewTravelCount = position - lastPos + 1;
// viewTravelCount = position - lastPos + 1;
mMode = MOVE_DOWN_POS;
} else {
// Already on screen, nothing to do
@ -64,8 +64,8 @@ public class ScrollerRunnable implements Runnable {
if (lastPos == mLastSeenPos) {
// No new views, let things keep going.
// mList.post(this);
// return;
// mList.post(this);
// return;
}
final View lastView = mList.getChildAt(lastViewIndex);
@ -86,8 +86,8 @@ public class ScrollerRunnable implements Runnable {
case MOVE_UP_POS: {
if (firstPos == mLastSeenPos) {
// No new views, let things keep going.
// mList.post(this);
// return;
// mList.post(this);
// return;
}
final View firstView = mList.getChildAt(0);

@ -33,23 +33,28 @@ import android.widget.AbsListView;
import android.widget.ListView;
/**
* A {@link android.view.View.OnTouchListener} that makes the list items in a {@link ListView}
* dismissable. {@link ListView} is given special treatment because by default it handles touches
* for its list items... i.e. it's in charge of drawing the pressed state (the list selector),
* handling list item clicks, etc.
* A {@link android.view.View.OnTouchListener} that makes the list items in a
* {@link ListView} dismissable. {@link ListView} is given special treatment
* because by default it handles touches for its list items... i.e. it's in
* charge of drawing the pressed state (the list selector), handling list item
* clicks, etc.
*
* <p>After creating the listener, the caller should also call {@link
* ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener)}, passing in the scroll
* listener returned by {@link #makeScrollListener()}. If a scroll listener is already assigned, the
* caller should still pass scroll changes through to this listener. This will ensure that this
* {@link SwipeDismissListViewTouchListener} is paused during list view scrolling.</p>
* <p>
* After creating the listener, the caller should also call
* {@link ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener)}
* , passing in the scroll listener returned by {@link #makeScrollListener()}.
* If a scroll listener is already assigned, the caller should still pass scroll
* changes through to this listener. This will ensure that this
* {@link SwipeDismissListViewTouchListener} is paused during list view
* scrolling.
* </p>
*
* <p>Example usage:</p>
* <p>
* Example usage:
* </p>
*
* <pre>
* SwipeDismissListViewTouchListener touchListener =
* new SwipeDismissListViewTouchListener(
* listView,
* SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView,
* new SwipeDismissListViewTouchListener.OnDismissCallback() {
* public void onDismiss(ListView listView, int[] reverseSortedPositions) {
* for (int position : reverseSortedPositions) {
@ -62,8 +67,10 @@ import android.widget.ListView;
* listView.setOnScrollListener(touchListener.makeScrollListener());
* </pre>
*
* <p>This class Requires API level 12 or later due to use of {@link
* android.view.ViewPropertyAnimator}.</p>
* <p>
* This class Requires API level 12 or later due to use of
* {@link android.view.ViewPropertyAnimator}.
* </p>
*/
public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
// Cached ViewConfiguration and system-wide constant values
@ -88,8 +95,9 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
private boolean mPaused;
/**
* The callback interface used by {@link SwipeDismissListViewTouchListener} to inform its client
* about a successful dismissal of one or more list item positions.
* The callback interface used by {@link SwipeDismissListViewTouchListener}
* to inform its client about a successful dismissal of one or more list
* item positions.
*/
public interface DismissCallbacks {
/**
@ -98,11 +106,13 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
boolean canDismiss(int position);
/**
* Called when the user has indicated they she would like to dismiss one or more list item
* positions.
* Called when the user has indicated they she would like to dismiss one
* or more list item positions.
*
* @param listView The originating {@link ListView}.
* @param reverseSortedPositions An array of positions to dismiss, sorted in descending
* @param listView
* The originating {@link ListView}.
* @param reverseSortedPositions
* An array of positions to dismiss, sorted in descending
* order for convenience.
*/
void onDismiss(ListView listView, int[] reverseSortedPositions);
@ -111,36 +121,41 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
/**
* Constructs a new swipe-to-dismiss touch listener for the given list view.
*
* @param listView The list view whose items should be dismissable.
* @param callbacks The callback to trigger when the user has indicated that she would like to
* dismiss one or more list items.
* @param listView
* The list view whose items should be dismissable.
* @param callbacks
* The callback to trigger when the user has indicated that she
* would like to dismiss one or more list items.
*/
public SwipeDismissListViewTouchListener(ListView listView, DismissCallbacks callbacks) {
ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
mSlop = Math.max(1, (int)(vc.getScaledTouchSlop() * 0.5f));
mSlop = Math.max(1, (int) (vc.getScaledTouchSlop() * 0.5f));
mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
mAnimationTime = listView.getContext().getResources().getInteger(
android.R.integer.config_shortAnimTime);
mAnimationTime = listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
mListView = listView;
mCallbacks = callbacks;
}
/**
* Enables or disables (pauses or resumes) watching for swipe-to-dismiss gestures.
* Enables or disables (pauses or resumes) watching for swipe-to-dismiss
* gestures.
*
* @param enabled Whether or not to watch for gestures.
* @param enabled
* Whether or not to watch for gestures.
*/
public void setEnabled(boolean enabled) {
mPaused = !enabled;
}
/**
* Returns an {@link android.widget.AbsListView.OnScrollListener} to be added to the {@link
* ListView} using {@link ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener)}.
* If a scroll listener is already assigned, the caller should still pass scroll changes through
* to this listener. This will ensure that this {@link SwipeDismissListViewTouchListener} is
* paused during list view scrolling.</p>
* Returns an {@link android.widget.AbsListView.OnScrollListener} to be
* added to the {@link ListView} using
* {@link ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener)}
* . If a scroll listener is already assigned, the caller should still pass
* scroll changes through to this listener. This will ensure that this
* {@link SwipeDismissListViewTouchListener} is paused during list view
* scrolling.</p>
*
* @see SwipeDismissListViewTouchListener
*/
@ -158,8 +173,8 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
}
/**
* Manually cause the item at the given position to be dismissed (trigger the dismiss
* animation).
* Manually cause the item at the given position to be dismissed (trigger
* the dismiss animation).
*/
public void dismiss(int position) {
dismiss(getViewForPosition(position), position, true);
@ -237,11 +252,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
dismiss(mDownView, mDownPosition, dismissRight);
} else {
// cancel
mDownView.animate()
.translationX(0)
.alpha(1)
.setDuration(mAnimationTime)
.setListener(null);
mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
}
mVelocityTracker.recycle();
mVelocityTracker = null;
@ -259,11 +270,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
if (mDownView != null) {
// cancel
mDownView.animate()
.translationX(0)
.alpha(1)
.setDuration(mAnimationTime)
.setListener(null);
mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
}
mVelocityTracker.recycle();
mVelocityTracker = null;
@ -287,17 +294,15 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
// Cancel ListView's touch (un-highlighting the item)
MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL |
(motionEvent.getActionIndex()
<< MotionEvent.ACTION_POINTER_INDEX_SHIFT));
cancelEvent.setAction(MotionEvent.ACTION_CANCEL
| (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
mListView.onTouchEvent(cancelEvent);
cancelEvent.recycle();
}
if (mSwiping) {
mDownView.setTranslationX(deltaX);
mDownView.setAlpha(Math.max(0.15f, Math.min(1f,
1f - 2f * Math.abs(deltaX) / mViewWidth)));
mDownView.setAlpha(Math.max(0.15f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
return true;
}
break;
@ -315,10 +320,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
return;
}
view.animate()
.translationX(dismissRight ? mViewWidth : -mViewWidth)
.alpha(0)
.setDuration(mAnimationTime)
view.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0).setDuration(mAnimationTime)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
@ -328,11 +330,8 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
}
private View getViewForPosition(int position) {
int index = position
- (mListView.getFirstVisiblePosition() - mListView.getHeaderViewsCount());
return (index >= 0 && index < mListView.getChildCount())
? mListView.getChildAt(index)
: null;
int index = position - (mListView.getFirstVisiblePosition() - mListView.getHeaderViewsCount());
return (index >= 0 && index < mListView.getChildCount()) ? mListView.getChildAt(index) : null;
}
class PendingDismissData implements Comparable<PendingDismissData> {

@ -15,35 +15,23 @@ public class ViewFlipperAnimations {
static {
// Setup the static TranslateAnimations for the ViewFlipper
BACK_IN = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1f,
Animation.RELATIVE_TO_PARENT, 0f,
0, 0f, 0, 0f
);
BACK_IN = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1f, Animation.RELATIVE_TO_PARENT, 0f, 0, 0f, 0,
0f);
BACK_IN.setInterpolator(new AccelerateDecelerateInterpolator());
BACK_IN.setDuration(300);
BACK_OUT = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0f,
Animation.RELATIVE_TO_PARENT, 1f,
0, 0f, 0, 0f
);
BACK_OUT = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 1f, 0, 0f, 0,
0f);
BACK_OUT.setInterpolator(new AccelerateDecelerateInterpolator());
BACK_OUT.setDuration(300);
NEXT_IN = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 1f,
Animation.RELATIVE_TO_PARENT, 0f,
0, 0f, 0, 0f
);
NEXT_IN = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1f, Animation.RELATIVE_TO_PARENT, 0f, 0, 0f, 0,
0f);
NEXT_IN.setInterpolator(new AccelerateDecelerateInterpolator());
NEXT_IN.setDuration(300);
NEXT_OUT = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0f,
Animation.RELATIVE_TO_PARENT, -1f,
0, 0f, 0, 0f
);
NEXT_OUT = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, -1f, 0, 0f,
0, 0f);
NEXT_OUT.setInterpolator(new AccelerateDecelerateInterpolator());
NEXT_OUT.setDuration(300);
}

@ -73,7 +73,8 @@ public class BoardEditor extends Activity {
}
private void removeBoard(String value) {
if (list.size() <= 1) return;
if (list.size() <= 1)
return;
for (int i = 0; i < list.size(); i++) {
Board e = list.get(i);
@ -95,8 +96,7 @@ public class BoardEditor extends Activity {
final EditText text = new EditText(this);
text.setSingleLine();
dialog = new AlertDialog.Builder(this)
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
dialog = new AlertDialog.Builder(this).setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
String value = text.getText().toString();
@ -105,15 +105,11 @@ public class BoardEditor extends Activity {
addBoard(value);
}
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
}
})
.setTitle(R.string.board_add)
.setView(text)
.create();
}).setTitle(R.string.board_add).setView(text).create();
text.requestFocus();
@ -143,7 +139,7 @@ public class BoardEditor extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
switch (item.getItemId()) {
case R.id.action_add_board:
showAddBoardDialog();
@ -153,8 +149,3 @@ public class BoardEditor extends Activity {
return super.onOptionsItemSelected(item);
}
}

@ -54,8 +54,3 @@ public class DeveloperActivity extends Activity {
setContentView(wrapper);
}
}

@ -77,8 +77,3 @@ public class ImagePickActivity extends Activity {
}
}
}

@ -38,7 +38,7 @@ public class ReplyActivity extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
switch (item.getItemId()) {
case android.R.id.home:
finish();

@ -63,10 +63,10 @@ public class BoardEditAdapter extends ArrayAdapter<Board> {
View view = inflater.inflate(R.layout.board_view, null);
TextView textView = (TextView)view.findViewById(R.id.board_view_text);
TextView textView = (TextView) view.findViewById(R.id.board_view_text);
textView.setText(text);
Button button = (Button)view.findViewById(R.id.board_view_delete);
Button button = (Button) view.findViewById(R.id.board_view_delete);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -82,4 +82,3 @@ public class BoardEditAdapter extends ArrayAdapter<Board> {
return true;
}
}

@ -12,7 +12,6 @@ import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
public class ImageViewAdapter extends FragmentStatePagerAdapter {
private final ImageViewActivity activity;
private final ArrayList<Post> postList = new ArrayList<Post>();
@ -33,27 +32,23 @@ public class ImageViewAdapter extends FragmentStatePagerAdapter {
}
public Post getPost(int position) {
if (position < 0 || position >= getCount()) return null;
if (position < 0 || position >= getCount())
return null;
return postList.get(position);
}
@Override
public void destroyItem(View collection, int position, Object o) {
View view = (View)o;
View view = (View) o;
((ViewPager) collection).removeView(view);
view = null;
}
public void setList(ArrayList<Post> list){
public void setList(ArrayList<Post> list) {
postList.clear();
postList.addAll(list);
notifyDataSetChanged();
}
}

@ -20,7 +20,6 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class PostAdapter extends BaseAdapter {
private final Context context;
private final ThreadManager threadManager;
@ -37,7 +36,8 @@ public class PostAdapter extends BaseAdapter {
@Override
public int getCount() {
if ((threadManager.getLoadable() != null && threadManager.getLoadable().isBoardMode()) || threadManager.shouldWatch()) {
if ((threadManager.getLoadable() != null && threadManager.getLoadable().isBoardMode())
|| threadManager.shouldWatch()) {
return postList.size() + 1;
} else {
return postList.size();
@ -157,8 +157,3 @@ public class PostAdapter extends BaseAdapter {
}
}
}

@ -17,7 +17,8 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
/**
* A DialogFragment that shows a list of posts. Use the newInstance method for instantiating.
* A DialogFragment that shows a list of posts. Use the newInstance method for
* instantiating.
*/
public class PostRepliesFragment extends DialogFragment {
private ListView listView;
@ -119,8 +120,3 @@ public class PostRepliesFragment extends DialogFragment {
}
}
}

@ -100,9 +100,8 @@ public class ReplyFragment extends DialogFragment {
Dialog dialog = getDialog();
Context context = getActivity();
String title = loadable.isThreadMode() ?
context.getString(R.string.reply) + " /" + loadable.board + "/" + loadable.no :
context.getString(R.string.reply_to_board) + " /" + loadable.board + "/";
String title = loadable.isThreadMode() ? context.getString(R.string.reply) + " /" + loadable.board + "/"
+ loadable.no : context.getString(R.string.reply_to_board) + " /" + loadable.board + "/";
if (dialog == null) {
getActivity().getActionBar().setTitle(title);
@ -115,10 +114,13 @@ public class ReplyFragment extends DialogFragment {
@Override
public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (page == 1) flipPage(0);
else if (page == 2) closeReply();
if (page == 1)
flipPage(0);
else if (page == 2)
closeReply();
return true;
} else return false;
} else
return false;
}
});
}
@ -177,24 +179,24 @@ public class ReplyFragment extends DialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
// Setup the views with listeners
container = inflater.inflate(R.layout.reply_view, null);
flipper = (ViewFlipper)container.findViewById(R.id.reply_flipper);
nameView = (FloatLabelEditText)container.findViewById(R.id.reply_name);
emailView = (FloatLabelEditText)container.findViewById(R.id.reply_email);
subjectView = (FloatLabelEditText)container.findViewById(R.id.reply_subject);
commentView = (FloatLabelEditText)container.findViewById(R.id.reply_comment);
imageViewContainer = (LoadView)container.findViewById(R.id.reply_image);
responseContainer = (LoadView)container.findViewById(R.id.reply_response);
captchaContainer = (LoadView)container.findViewById(R.id.reply_captcha_container);
flipper = (ViewFlipper) container.findViewById(R.id.reply_flipper);
nameView = (FloatLabelEditText) container.findViewById(R.id.reply_name);
emailView = (FloatLabelEditText) container.findViewById(R.id.reply_email);
subjectView = (FloatLabelEditText) container.findViewById(R.id.reply_subject);
commentView = (FloatLabelEditText) container.findViewById(R.id.reply_comment);
imageViewContainer = (LoadView) container.findViewById(R.id.reply_image);
responseContainer = (LoadView) container.findViewById(R.id.reply_response);
captchaContainer = (LoadView) container.findViewById(R.id.reply_captcha_container);
captchaContainer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
getCaptcha();
}
});
captchaText = (TextView)container.findViewById(R.id.reply_captcha);
captchaText = (TextView) container.findViewById(R.id.reply_captcha);
cancelButton = (Button)container.findViewById(R.id.reply_cancel);
cancelButton = (Button) container.findViewById(R.id.reply_cancel);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -206,7 +208,7 @@ public class ReplyFragment extends DialogFragment {
}
});
fileButton = (Button)container.findViewById(R.id.reply_file);
fileButton = (Button) container.findViewById(R.id.reply_file);
fileButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -224,7 +226,7 @@ public class ReplyFragment extends DialogFragment {
}
});
fileDeleteButton = (Button)container.findViewById(R.id.reply_file_delete);
fileDeleteButton = (Button) container.findViewById(R.id.reply_file_delete);
fileDeleteButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -232,7 +234,7 @@ public class ReplyFragment extends DialogFragment {
}
});
submitButton = (Button)container.findViewById(R.id.reply_submit);
submitButton = (Button) container.findViewById(R.id.reply_submit);
submitButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -241,7 +243,8 @@ public class ReplyFragment extends DialogFragment {
} else if (page == 1) {
flipPage(2);
submit();
};
}
;
}
});
@ -257,7 +260,8 @@ public class ReplyFragment extends DialogFragment {
}
/**
* Set if the dialog is able to be closed, by pressing outside of the dialog, or something else.
* Set if the dialog is able to be closed, by pressing outside of the
* dialog, or something else.
*/
private void setClosable(boolean e) {
if (getDialog() != null) {
@ -267,9 +271,11 @@ public class ReplyFragment extends DialogFragment {
}
/**
* Flip to an page with an animation.
* Sets the correct text on the cancelButton:
* @param position 0-2
* Flip to an page with an animation. Sets the correct text on the
* cancelButton:
*
* @param position
* 0-2
*/
private void flipPage(int position) {
boolean flipBack = position < page;
@ -296,10 +302,11 @@ public class ReplyFragment extends DialogFragment {
}
/**
* Set the picked image in the imageView.
* Sets the file in the draft.
* Call null on the file to empty the imageView.
* @param imagePath file to image to send or null to clear
* Set the picked image in the imageView. Sets the file in the draft. Call
* null on the file to empty the imageView.
*
* @param imagePath
* file to image to send or null to clear
*/
private void setFile(final File file) {
draft.file = file;
@ -339,7 +346,8 @@ public class ReplyFragment extends DialogFragment {
}
private void getCaptcha() {
if (gettingCaptcha) return;
if (gettingCaptcha)
return;
gettingCaptcha = true;
captchaContainer.setView(null);
@ -349,7 +357,8 @@ public class ReplyFragment extends DialogFragment {
ChanApplication.getVolleyRequestQueue().add(new StringRequest(Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String result) {
if (!isVisible()) return;
if (!isVisible())
return;
String challenge = ReplyManager.getChallenge(result);
if (challenge != null) {
@ -407,13 +416,16 @@ public class ReplyFragment extends DialogFragment {
/**
* Got response about or reply from ReplyManager
*
* @param response
*/
private void handleSubmitResponse(ReplyResponse response) {
if (getActivity() == null) return;
if (getActivity() == null)
return;
if (response.isNetworkError || response.isUserError) {
int resId = response.isCaptchaError ? R.string.reply_error_captcha : (response.isFileError ? R.string.reply_error_file : R.string.reply_error);
int resId = response.isCaptchaError ? R.string.reply_error_captcha
: (response.isFileError ? R.string.reply_error_file : R.string.reply_error);
Toast.makeText(getActivity(), resId, Toast.LENGTH_LONG).show();
submitButton.setEnabled(true);
cancelButton.setEnabled(true);
@ -424,7 +436,7 @@ public class ReplyFragment extends DialogFragment {
} else if (response.isSuccessful) {
shouldSaveDraft = false;
Toast.makeText(getActivity(), R.string.reply_success, Toast.LENGTH_SHORT).show();
// threadFragment.reload(); // won't work: it takes 4chan a variable time to process the reply
// threadFragment.reload(); // won't work: it takes 4chan a variable time to process the reply
closeReply();
} else {
if (isVisible()) {
@ -442,8 +454,3 @@ public class ReplyFragment extends DialogFragment {
}
}
}

@ -48,8 +48,8 @@ public class SettingsFragment extends PreferenceFragment {
ChanPreferences.setDeveloper(enabled);
updateDeveloperPreference();
Toast.makeText(getActivity(),
(enabled ? "Enabled " : "Disabled ") + "developer options", Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), (enabled ? "Enabled " : "Disabled ") + "developer options",
Toast.LENGTH_LONG).show();
}
return true;
@ -78,7 +78,8 @@ public class SettingsFragment extends PreferenceFragment {
final Preference watchPreference = findPreference("watch_settings");
if (watchPreference != null) {
watchPreference.setSummary(ChanPreferences.getWatchEnabled() ? R.string.watch_summary_enabled : R.string.watch_summary_disabled);
watchPreference.setSummary(ChanPreferences.getWatchEnabled() ? R.string.watch_summary_enabled
: R.string.watch_summary_disabled);
}
}

@ -138,10 +138,12 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana
if (threadManager.getLoadable().isThreadMode()) {
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {}
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
if (loadable != null) {
loadable.listViewIndex = view.getFirstVisiblePosition();
View v = view.getChildAt(0);
@ -176,6 +178,7 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana
/**
* Returns an TextView containing the appropriate error message
*
* @param error
* @return
*/
@ -222,8 +225,3 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana
}
}
}

@ -46,19 +46,20 @@ import android.widget.ListView;
* The dynamic listview is an extension of listview that supports cell dragging
* and swapping.
*
* This layout is in charge of positioning the hover cell in the correct location
* on the screen in response to user touch events. It uses the position of the
* hover cell to determine when two cells should be swapped. If two cells should
* be swapped, all the corresponding data set and layout changes are handled here.
* This layout is in charge of positioning the hover cell in the correct
* location on the screen in response to user touch events. It uses the position
* of the hover cell to determine when two cells should be swapped. If two cells
* should be swapped, all the corresponding data set and layout changes are
* handled here.
*
* If no cell is selected, all the touch events are passed down to the listview
* and behave normally. If one of the items in the listview experiences a
* long press event, the contents of its current visible state are captured as
* a bitmap and its visibility is set to INVISIBLE. A hover cell is then created and
* added to this layout as an overlaying BitmapDrawable above the listview. Once the
* hover cell is translated some distance to signify an item swap, a data set change
* accompanied by animation takes place. When the user releases the hover cell,
* it animates into its corresponding position in the listview.
* and behave normally. If one of the items in the listview experiences a long
* press event, the contents of its current visible state are captured as a
* bitmap and its visibility is set to INVISIBLE. A hover cell is then created
* and added to this layout as an overlaying BitmapDrawable above the listview.
* Once the hover cell is translated some distance to signify an item swap, a
* data set change accompanied by animation takes place. When the user releases
* the hover cell, it animates into its corresponding position in the listview.
*
* When the hover cell is either above or below the bounds of the listview, this
* listview also scrolls on its own so as to reveal additional content.
@ -116,15 +117,14 @@ public class DynamicListView<T> extends ListView {
setOnItemLongClickListener(mOnItemLongClickListener);
setOnScrollListener(mScrollListener);
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
mSmoothScrollAmountAtEdge = (int)(SMOOTH_SCROLL_AMOUNT_AT_EDGE / metrics.density);
mSmoothScrollAmountAtEdge = (int) (SMOOTH_SCROLL_AMOUNT_AT_EDGE / metrics.density);
}
/**
* Listens for long clicks on any items in the listview. When a cell has
* been selected, the hover cell is created and set up.
*/
private final AdapterView.OnItemLongClickListener mOnItemLongClickListener =
new AdapterView.OnItemLongClickListener() {
private final AdapterView.OnItemLongClickListener mOnItemLongClickListener = new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
mTotalOffset = 0;
@ -190,7 +190,7 @@ public class DynamicListView<T> extends ListView {
/** Returns a bitmap showing a screenshot of the view passed in. */
private Bitmap getBitmapFromView(View v) {
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas (bitmap);
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
return bitmap;
}
@ -198,21 +198,21 @@ public class DynamicListView<T> extends ListView {
/**
* Stores a reference to the views above and below the item currently
* corresponding to the hover cell. It is important to note that if this
* item is either at the top or bottom of the list, mAboveItemId or mBelowItemId
* may be invalid.
* item is either at the top or bottom of the list, mAboveItemId or
* mBelowItemId may be invalid.
*/
private void updateNeighborViewsForID(long itemID) {
int position = getPositionForID(itemID);
BoardEditAdapter adapter = ((BoardEditAdapter)getAdapter());
BoardEditAdapter adapter = ((BoardEditAdapter) getAdapter());
mAboveItemId = adapter.getItemId(position - 1);
mBelowItemId = adapter.getItemId(position + 1);
}
/** Retrieves the view in the list corresponding to itemID */
public View getViewForID (long itemID) {
public View getViewForID(long itemID) {
int firstVisiblePosition = getFirstVisiblePosition();
BoardEditAdapter adapter = ((BoardEditAdapter)getAdapter());
for(int i = 0; i < getChildCount(); i++) {
BoardEditAdapter adapter = ((BoardEditAdapter) getAdapter());
for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
int position = firstVisiblePosition + i;
long id = adapter.getItemId(position);
@ -224,7 +224,7 @@ public class DynamicListView<T> extends ListView {
}
/** Retrieves the position in the list corresponding to itemID */
public int getPositionForID (long itemID) {
public int getPositionForID(long itemID) {
View v = getViewForID(itemID);
if (v == null) {
return -1;
@ -247,12 +247,12 @@ public class DynamicListView<T> extends ListView {
}
@Override
public boolean onTouchEvent (MotionEvent event) {
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mDownX = (int)event.getX();
mDownY = (int)event.getY();
mDownX = (int) event.getX();
mDownY = (int) event.getY();
mActivePointerId = event.getPointerId(0);
break;
case MotionEvent.ACTION_MOVE:
@ -266,8 +266,8 @@ public class DynamicListView<T> extends ListView {
int deltaY = mLastEventY - mDownY;
if (mCellIsMobile) {
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mHoverCellOriginalBounds.top + deltaY
+ mTotalOffset);
mHoverCell.setBounds(mHoverCellCurrentBounds);
invalidate();
@ -290,8 +290,7 @@ public class DynamicListView<T> extends ListView {
* the movement of the hover cell has ended, then the dragging event
* ends and the hover cell is animated to its corresponding position
* in the listview. */
pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
MotionEvent.ACTION_POINTER_INDEX_SHIFT;
pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = event.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
touchEventsEnded();
@ -307,11 +306,11 @@ public class DynamicListView<T> extends ListView {
/**
* This method determines whether the hover cell has been shifted far enough
* to invoke a cell swap. If so, then the respective cell swap candidate is
* determined and the data set is changed. Upon posting a notification of the
* data set change, a layout is invoked to place the cells in the right place.
* Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
* offset the cell being swapped to where it previously was and then animate it to
* its new position.
* determined and the data set is changed. Upon posting a notification of
* the data set change, a layout is invoked to place the cells in the right
* place. Using a ViewTreeObserver and a corresponding OnPreDrawListener, we
* can offset the cell being swapped to where it previously was and then
* animate it to its new position.
*/
private void handleCellSwitch() {
final int deltaY = mLastEventY - mDownY;
@ -363,8 +362,7 @@ public class DynamicListView<T> extends ListView {
switchView.setTranslationY(delta);
ObjectAnimator animator = ObjectAnimator.ofFloat(switchView,
View.TRANSLATION_Y, 0);
ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, View.TRANSLATION_Y, 0);
animator.setDuration(MOVE_DURATION);
animator.start();
@ -380,14 +378,13 @@ public class DynamicListView<T> extends ListView {
arrayList.set(indexTwo, temp);
}
/**
* Resets all the appropriate fields to a default state while also animating
* the hover cell back to its correct location.
*/
private void touchEventsEnded () {
private void touchEventsEnded() {
final View mobileView = getViewForID(mMobileItemId);
if (mCellIsMobile|| mIsWaitingForScrollFinish) {
if (mCellIsMobile || mIsWaitingForScrollFinish) {
mCellIsMobile = false;
mIsWaitingForScrollFinish = false;
mIsMobileScrolling = false;
@ -403,8 +400,8 @@ public class DynamicListView<T> extends ListView {
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop());
ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds",
sBoundEvaluator, mHoverCellCurrentBounds);
ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator,
mHoverCellCurrentBounds);
hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
@ -437,7 +434,7 @@ public class DynamicListView<T> extends ListView {
/**
* Resets all the appropriate fields to a default state.
*/
private void touchEventsCancelled () {
private void touchEventsCancelled() {
View mobileView = getViewForID(mMobileItemId);
if (mCellIsMobile) {
mAboveItemId = INVALID_ID;
@ -460,28 +457,27 @@ public class DynamicListView<T> extends ListView {
private final static TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {
@Override
public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
return new Rect(interpolate(startValue.left, endValue.left, fraction),
interpolate(startValue.top, endValue.top, fraction),
interpolate(startValue.right, endValue.right, fraction),
interpolate(startValue.bottom, endValue.bottom, fraction));
return new Rect(interpolate(startValue.left, endValue.left, fraction), interpolate(startValue.top,
endValue.top, fraction), interpolate(startValue.right, endValue.right, fraction), interpolate(
startValue.bottom, endValue.bottom, fraction));
}
public int interpolate(int start, int end, float fraction) {
return (int)(start + fraction * (end - start));
return (int) (start + fraction * (end - start));
}
};
/**
* Determines whether this listview is in a scrolling state invoked
* by the fact that the hover cell is out of the bounds of the listview;
* Determines whether this listview is in a scrolling state invoked by the
* fact that the hover cell is out of the bounds of the listview;
*/
private void handleMobileCellScroll() {
mIsMobileScrolling = handleMobileCellScroll(mHoverCellCurrentBounds);
}
/**
* This method is in charge of determining if the hover cell is above
* or below the bounds of the listview. If so, the listview does an appropriate
* This method is in charge of determining if the hover cell is above or
* below the bounds of the listview. If so, the listview does an appropriate
* upward or downward smooth scroll so as to reveal new items.
*/
public boolean handleMobileCellScroll(Rect r) {
@ -510,13 +506,14 @@ public class DynamicListView<T> extends ListView {
}
/**
* This scroll listener is added to the listview in order to handle cell swapping
* when the cell is either at the top or bottom edge of the listview. If the hover
* cell is at either edge of the listview, the listview will begin scrolling. As
* scrolling takes place, the listview continuously checks if new cells became visible
* and determines whether they are potential candidates for a cell swap.
* This scroll listener is added to the listview in order to handle cell
* swapping when the cell is either at the top or bottom edge of the
* listview. If the hover cell is at either edge of the listview, the
* listview will begin scrolling. As scrolling takes place, the listview
* continuously checks if new cells became visible and determines whether
* they are potential candidates for a cell swap.
*/
private final AbsListView.OnScrollListener mScrollListener = new AbsListView.OnScrollListener () {
private final AbsListView.OnScrollListener mScrollListener = new AbsListView.OnScrollListener() {
private int mPreviousFirstVisibleItem = -1;
private int mPreviousVisibleItemCount = -1;
@ -525,8 +522,7 @@ public class DynamicListView<T> extends ListView {
private int mCurrentScrollState;
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mCurrentFirstVisibleItem = firstVisibleItem;
mCurrentVisibleItemCount = visibleItemCount;
@ -550,12 +546,12 @@ public class DynamicListView<T> extends ListView {
}
/**
* This method is in charge of invoking 1 of 2 actions. Firstly, if the listview
* is in a state of scrolling invoked by the hover cell being outside the bounds
* of the listview, then this scrolling event is continued. Secondly, if the hover
* cell has already been released, this invokes the animation for the hover cell
* to return to its correct position after the listview has entered an idle scroll
* state.
* This method is in charge of invoking 1 of 2 actions. Firstly, if the
* listview is in a state of scrolling invoked by the hover cell being
* outside the bounds of the listview, then this scrolling event is
* continued. Secondly, if the hover cell has already been released,
* this invokes the animation for the hover cell to return to its
* correct position after the listview has entered an idle scroll state.
*/
private void isScrollCompleted() {
if (mCurrentVisibleItemCount > 0 && mCurrentScrollState == SCROLL_STATE_IDLE) {
@ -568,8 +564,9 @@ public class DynamicListView<T> extends ListView {
}
/**
* Determines if the listview scrolled up enough to reveal a new cell at the
* top of the list. If so, then the appropriate parameters are updated.
* Determines if the listview scrolled up enough to reveal a new cell at
* the top of the list. If so, then the appropriate parameters are
* updated.
*/
public void checkAndHandleFirstVisibleCellChange() {
if (mCurrentFirstVisibleItem != mPreviousFirstVisibleItem) {
@ -581,8 +578,9 @@ public class DynamicListView<T> extends ListView {
}
/**
* Determines if the listview scrolled down enough to reveal a new cell at the
* bottom of the list. If so, then the appropriate parameters are updated.
* Determines if the listview scrolled down enough to reveal a new cell
* at the bottom of the list. If so, then the appropriate parameters are
* updated.
*/
public void checkAndHandleLastVisibleCellChange() {
int currentLastVisibleItem = mCurrentFirstVisibleItem + mCurrentVisibleItemCount;

@ -69,13 +69,13 @@ public class GIFView extends View {
dur = 1000;
}
int relTime = (int)((now - movieStart) % dur);
int relTime = (int) ((now - movieStart) % dur);
movie.setTime(relTime);
canvas.save();
float width = (float)getWidth() / (float)movie.width();
float height = (float)getHeight() / (float)movie.height();
float width = (float) getWidth() / (float) movie.width();
float height = (float) getHeight() / (float) movie.height();
float scale = width > height ? height : width;
@ -94,8 +94,3 @@ public class GIFView extends View {
}
}
}

@ -12,9 +12,8 @@ import android.widget.Toast;
import com.android.volley.VolleyError;
/**
* Extends NetworkImageView.
* Attaches a PhotoViewAttacher when setBitmap is called.
* Sets the progressBar to false when a bitmap gets set.
* Extends NetworkImageView. Attaches a PhotoViewAttacher when setBitmap is
* called. Sets the progressBar to false when a bitmap gets set.
*/
public class NetworkPhotoView extends CustomNetworkImageView {
private PhotoViewAttacher attacher;
@ -70,8 +69,3 @@ public class NetworkPhotoView extends CustomNetworkImageView {
}
}
}

@ -67,7 +67,8 @@ public class ThreadWatchCounterView extends TextView implements View.OnClickList
private void updateCounterText(ThreadManager threadManager) {
Loader loader = tm.getLoader();
if (loader == null) return;
if (loader == null)
return;
int time = Math.round(loader.getTimeUntilLoadMore() / 1000f);
@ -78,7 +79,3 @@ public class ThreadWatchCounterView extends TextView implements View.OnClickList
}
}
}

@ -25,6 +25,7 @@ public class IOUtils {
/**
* Copies the inputstream to the outputstream and closes both streams.
*
* @param is
* @param os
* @throws IOException

@ -12,6 +12,7 @@ public class IconCache {
/**
* Load the icons in the cache. Lightweight icons only! Icons can be null!
*
* @param context
*/
public static void createIcons(final Context context) {

@ -14,7 +14,8 @@ import android.graphics.BitmapFactory;
*/
public class ImageDecoder {
public static Bitmap decodeFile(File file, int maxWidth, int maxHeight) {
if (!file.exists()) return null;
if (!file.exists())
return null;
FileInputStream fis;
@ -60,25 +61,19 @@ public class ImageDecoder {
int actualHeight = decodeOptions.outHeight;
// Then compute the dimensions we would ideally like to decode to.
int desiredWidth = getResizedDimension(maxWidth, maxHeight,
actualWidth, actualHeight);
int desiredHeight = getResizedDimension(maxHeight, maxWidth,
actualHeight, actualWidth);
int desiredWidth = getResizedDimension(maxWidth, maxHeight, actualWidth, actualHeight);
int desiredHeight = getResizedDimension(maxHeight, maxWidth, actualHeight, actualWidth);
// Decode to the nearest power of two scaling factor.
decodeOptions.inJustDecodeBounds = false;
// decodeOptions.inPreferQualityOverSpeed = PREFER_QUALITY_OVER_SPEED;
decodeOptions.inSampleSize =
findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
Bitmap tempBitmap =
BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
decodeOptions.inSampleSize = findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
Bitmap tempBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
// If necessary, scale down to the maximal acceptable size.
if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth ||
tempBitmap.getHeight() > desiredHeight)) {
bitmap = Bitmap.createScaledBitmap(tempBitmap,
desiredWidth, desiredHeight, true);
if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth || tempBitmap.getHeight() > desiredHeight)) {
bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth, desiredHeight, true);
tempBitmap.recycle();
} else {
bitmap = tempBitmap;

@ -46,7 +46,8 @@ public class ImageSaver {
throw new IOException(errorReason);
}
File path = new File(Environment.getExternalStorageDirectory() + File.separator + ChanPreferences.getImageSaveDirectory());
File path = new File(Environment.getExternalStorageDirectory() + File.separator
+ ChanPreferences.getImageSaveDirectory());
if (!path.exists()) {
if (!path.mkdirs()) {
@ -58,7 +59,7 @@ public class ImageSaver {
File file = new File(path, name + "." + extension);
int nextFileNameNumber = 0;
String newName;
while(file.exists()) {
while (file.exists()) {
newName = name + "_" + Integer.toString(nextFileNameNumber) + "." + extension;
file = new File(path, newName);
nextFileNameNumber++;
@ -70,7 +71,8 @@ public class ImageSaver {
outputStream.write(data);
outputStream.close();
MediaScannerConnection.scanFile(context, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {
MediaScannerConnection.scanFile(context, new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Logger.i(TAG, "Media scan succeeded: " + uri);
@ -82,14 +84,10 @@ public class ImageSaver {
} catch (IOException e) {
e.printStackTrace();
if (errorReason == null) errorReason = context.getString(R.string.image_save_failed);
if (errorReason == null)
errorReason = context.getString(R.string.image_save_failed);
Toast.makeText(context, errorReason, Toast.LENGTH_LONG).show();
}
}
}

@ -72,4 +72,3 @@ public class Logger {
}
}
}

@ -14,13 +14,17 @@ import android.view.ViewGroup;
public class Utils {
private static DisplayMetrics displayMetrics;
public final static ViewGroup.LayoutParams MATCH_PARAMS = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
public final static ViewGroup.LayoutParams WRAP_PARAMS = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
public final static ViewGroup.LayoutParams MATCH_WRAP_PARAMS = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
public final static ViewGroup.LayoutParams WRAP_MATCH_PARAMS = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
public final static ViewGroup.LayoutParams MATCH_PARAMS = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
public final static ViewGroup.LayoutParams WRAP_PARAMS = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
public final static ViewGroup.LayoutParams MATCH_WRAP_PARAMS = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
public final static ViewGroup.LayoutParams WRAP_MATCH_PARAMS = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
public static int dp(float dp) {
// return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
// return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
if (displayMetrics == null) {
displayMetrics = ChanApplication.getInstance().getResources().getDisplayMetrics();
}
@ -29,7 +33,9 @@ public class Utils {
}
/**
* Sets the android.R.attr.selectableItemBackground as background drawable on the view.
* Sets the android.R.attr.selectableItemBackground as background drawable
* on the view.
*
* @param view
*/
@SuppressWarnings("deprecation")
@ -39,8 +45,7 @@ public class Utils {
}
public static Drawable getSelectableBackgroundDrawable(Context context) {
TypedArray arr = context.obtainStyledAttributes(
new int[] {android.R.attr.selectableItemBackground});
TypedArray arr = context.obtainStyledAttributes(new int[] { android.R.attr.selectableItemBackground });
Drawable drawable = arr.getDrawable(0);
@ -50,8 +55,9 @@ public class Utils {
}
/**
* Causes the runnable to be added to the message queue.
* The runnable will be run on the ui thread.
* Causes the runnable to be added to the message queue. The runnable will
* be run on the ui thread.
*
* @param runnable
*/
public static void runOnUiThread(Runnable runnable) {

Loading…
Cancel
Save