Format code

captchafix
Florens Douwes 11 years ago
parent 4293a41830
commit 30724d2148
  1. 5
      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. 16
      Chan/src/org/floens/chan/core/manager/BoardManager.java
  5. 65
      Chan/src/org/floens/chan/core/manager/ReplyManager.java
  6. 3
      Chan/src/org/floens/chan/core/manager/ThreadManager.java
  7. 8
      Chan/src/org/floens/chan/core/model/Board.java
  8. 23
      Chan/src/org/floens/chan/core/model/Loadable.java
  9. 7
      Chan/src/org/floens/chan/core/model/Pin.java
  10. 4
      Chan/src/org/floens/chan/core/model/PostLinkable.java
  11. 4
      Chan/src/org/floens/chan/core/net/ByteArrayRequest.java
  12. 21
      Chan/src/org/floens/chan/core/net/ChanReaderRequest.java
  13. 4
      Chan/src/org/floens/chan/core/net/GIFRequest.java
  14. 4
      Chan/src/org/floens/chan/core/net/JsonReaderRequest.java
  15. 5
      Chan/src/org/floens/chan/database/DatabaseHelper.java
  16. 5
      Chan/src/org/floens/chan/database/DatabaseManager.java
  17. 117
      Chan/src/org/floens/chan/ui/SwipeDismissListViewTouchListener.java
  18. 28
      Chan/src/org/floens/chan/ui/ViewFlipperAnimations.java
  19. 19
      Chan/src/org/floens/chan/ui/activity/BoardEditor.java
  20. 5
      Chan/src/org/floens/chan/ui/activity/DeveloperActivity.java
  21. 5
      Chan/src/org/floens/chan/ui/activity/ImagePickActivity.java
  22. 1
      Chan/src/org/floens/chan/ui/adapter/BoardEditAdapter.java
  23. 9
      Chan/src/org/floens/chan/ui/adapter/ImageViewAdapter.java
  24. 9
      Chan/src/org/floens/chan/ui/adapter/PostAdapter.java
  25. 8
      Chan/src/org/floens/chan/ui/fragment/PostRepliesFragment.java
  26. 55
      Chan/src/org/floens/chan/ui/fragment/ReplyFragment.java
  27. 7
      Chan/src/org/floens/chan/ui/fragment/SettingsFragment.java
  28. 12
      Chan/src/org/floens/chan/ui/fragment/ThreadFragment.java
  29. 106
      Chan/src/org/floens/chan/ui/view/DynamicListView.java
  30. 5
      Chan/src/org/floens/chan/ui/view/GIFView.java
  31. 10
      Chan/src/org/floens/chan/ui/view/NetworkPhotoView.java
  32. 7
      Chan/src/org/floens/chan/ui/view/ThreadWatchCounterView.java
  33. 1
      Chan/src/org/floens/chan/utils/IOUtils.java
  34. 1
      Chan/src/org/floens/chan/utils/IconCache.java
  35. 21
      Chan/src/org/floens/chan/utils/ImageDecoder.java
  36. 14
      Chan/src/org/floens/chan/utils/ImageSaver.java
  37. 1
      Chan/src/org/floens/chan/utils/Logger.java
  38. 24
      Chan/src/org/floens/chan/utils/Utils.java

@ -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);
}
}

@ -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;

@ -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()) {
@ -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 {
@ -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);
}

@ -83,8 +83,3 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
}
}

@ -133,8 +133,3 @@ public class DatabaseManager {
loadSavedReplies();
}
}

@ -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));
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();
@ -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 {
}
}
}

@ -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,7 +32,8 @@ 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);
}
@ -52,8 +52,3 @@ public class ImageViewAdapter extends FragmentStatePagerAdapter {
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;
}
});
}
@ -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);
@ -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.
@ -123,8 +124,7 @@ public class DynamicListView<T> extends ListView {
* 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;
@ -198,8 +198,8 @@ 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);
@ -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,7 +378,6 @@ 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.
@ -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) {
@ -460,10 +457,9 @@ 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) {
@ -472,16 +468,16 @@ public class DynamicListView<T> extends 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;
* 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,11 +506,12 @@ 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() {
@ -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;

@ -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()) {
@ -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,10 +14,14 @@ 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());
@ -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