Fixed inconsistency in ImagePickActivity

captchafix
Florens Douwes 11 years ago
parent 65d09ba0fb
commit ebbfb3a33e
  1. 28
      Chan/src/org/floens/chan/ChanApplication.java
  2. 40
      Chan/src/org/floens/chan/activity/ImagePickActivity.java
  3. 6
      Chan/src/org/floens/chan/model/PostLinkable.java
  4. 42
      Chan/src/org/floens/chan/service/PinnedService.java

@ -18,58 +18,58 @@ import com.android.volley.toolbox.Volley;
public class ChanApplication extends Application { public class ChanApplication extends Application {
public static final boolean DEVELOPER_MODE = true; public static final boolean DEVELOPER_MODE = true;
private static ChanApplication instance; private static ChanApplication instance;
private static RequestQueue volleyRequestQueue; private static RequestQueue volleyRequestQueue;
private static ImageLoader imageLoader; private static ImageLoader imageLoader;
public ChanApplication() { public ChanApplication() {
instance = this; instance = this;
} }
public static ChanApplication getInstance() { public static ChanApplication getInstance() {
return instance; return instance;
} }
public static RequestQueue getVolleyRequestQueue() { public static RequestQueue getVolleyRequestQueue() {
return volleyRequestQueue; return volleyRequestQueue;
} }
public static ImageLoader getImageLoader() { public static ImageLoader getImageLoader() {
return imageLoader; return imageLoader;
} }
public static SharedPreferences getPreferences() { public static SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(instance); return PreferenceManager.getDefaultSharedPreferences(instance);
} }
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
if (ChanApplication.DEVELOPER_MODE) { if (ChanApplication.DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll() .detectAll()
.penaltyLog() .penaltyLog()
.build()); .build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll() .detectAll()
.penaltyLog() .penaltyLog()
.build()); .build());
} }
IconCache.createIcons(this); IconCache.createIcons(this);
volleyRequestQueue = Volley.newRequestQueue(this); volleyRequestQueue = Volley.newRequestQueue(this);
imageLoader = new ImageLoader(volleyRequestQueue, new BitmapLruImageCache(1024 * 1024 * 8)); imageLoader = new ImageLoader(volleyRequestQueue, new BitmapLruImageCache(1024 * 1024 * 8));
new DatabaseManager(this); new DatabaseManager(this);
new BoardManager(this); new BoardManager(this);
new PinnedManager(this); new PinnedManager(this);
new ReplyManager(this); new ReplyManager(this);
// startService(new Intent(this, PinnedService.class)); // startService(new Intent(this, PinnedService.class));
} }
} }

@ -7,6 +7,7 @@ import java.io.InputStream;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.manager.ReplyManager; import org.floens.chan.manager.ReplyManager;
import org.floens.chan.utils.IOUtils;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
@ -17,62 +18,55 @@ import android.widget.Toast;
public class ImagePickActivity extends Activity { public class ImagePickActivity extends Activity {
private static final int IMAGE_RESULT = 1; private static final int IMAGE_RESULT = 1;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*"); intent.setType("image/*");
try { try {
startActivityForResult(intent, IMAGE_RESULT); startActivityForResult(intent, IMAGE_RESULT);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
Toast.makeText(this, R.string.image_open_failed, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.image_open_failed, Toast.LENGTH_LONG).show();
finish(); finish();
} }
} }
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
finish(); finish();
if (requestCode == IMAGE_RESULT && resultCode == Activity.RESULT_OK) { if (requestCode == IMAGE_RESULT && resultCode == Activity.RESULT_OK) {
if (data != null) { if (data != null) {
final Uri uri = data.getData(); final Uri uri = data.getData();
ReplyManager.getInstance()._onPickedFileLoading(); ReplyManager.getInstance()._onPickedFileLoading();
// Async load the stream into "pickedFileCache", an file in the cache root // Async load the stream into "pickedFileCache", an file in the cache root
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
InputStream is = getContentResolver().openInputStream(uri);
final File cacheFile = new File(getCacheDir() + File.separator + "pickedFileCache"); final File cacheFile = new File(getCacheDir() + File.separator + "pickedFileCache");
if (cacheFile.exists()) { if (cacheFile.exists()) {
cacheFile.delete(); cacheFile.delete();
} }
FileOutputStream fis = new FileOutputStream(cacheFile); InputStream is = getContentResolver().openInputStream(uri);
FileOutputStream fos = new FileOutputStream(cacheFile);
byte[] buffer = new byte[1024];
int length = 0; IOUtils.copy(is, fos);
while((length = is.read(buffer)) != -1) {
fis.write(buffer, 0, length);
}
is.close();
fis.close();
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
ReplyManager.getInstance()._onPickedFile(cacheFile); ReplyManager.getInstance()._onPickedFile(cacheFile);
} }
}); });
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

@ -10,12 +10,12 @@ import android.view.View;
*/ */
public class PostLinkable extends ClickableSpan { public class PostLinkable extends ClickableSpan {
public static enum Type {QUOTE, LINK}; public static enum Type {QUOTE, LINK};
public final Post post; public final Post post;
public final String key; public final String key;
public final String value; public final String value;
public final Type type; public final Type type;
public PostLinkable(Post post, String key, String value, Type type) { public PostLinkable(Post post, String key, String value, Type type) {
this.post = post; this.post = post;
this.key = key; this.key = key;
@ -29,7 +29,7 @@ public class PostLinkable extends ClickableSpan {
post.getLinkableListener().onLinkableClick(this); post.getLinkableListener().onLinkableClick(this);
} }
} }
@Override @Override
public void updateDrawState(TextPaint ds) { public void updateDrawState(TextPaint ds) {
ds.setColor(type == Type.QUOTE ? Color.argb(255, 221, 0, 0) : Color.argb(255, 0, 0, 180)); ds.setColor(type == Type.QUOTE ? Color.argb(255, 221, 0, 0) : Color.argb(255, 0, 0, 180));

@ -18,17 +18,17 @@ import android.os.Looper;
public class PinnedService extends Service { public class PinnedService extends Service {
private static final long FOREGROUND_INTERVAL = 10000L; private static final long FOREGROUND_INTERVAL = 10000L;
private static final long BACKGROUND_INTERVAL = 60000L; private static final long BACKGROUND_INTERVAL = 60000L;
private static PinnedService instance; private static PinnedService instance;
private static boolean activityInForeground = false; private static boolean activityInForeground = false;
private Thread loadThread; private Thread loadThread;
private boolean running = true; private boolean running = true;
public PinnedService() { public PinnedService() {
instance = this; instance = this;
} }
/** /**
* Get the PinnedService instance * Get the PinnedService instance
* @return the instance or null * @return the instance or null
@ -36,31 +36,31 @@ public class PinnedService extends Service {
public static PinnedService getInstance() { public static PinnedService getInstance() {
return instance; return instance;
} }
public static void onActivityStart() { public static void onActivityStart() {
Logger.test("onActivityStart"); Logger.test("onActivityStart");
activityInForeground = true; activityInForeground = true;
} }
public static void onActivityStop() { public static void onActivityStop() {
Logger.test("onActivityStop"); Logger.test("onActivityStop");
activityInForeground = false; activityInForeground = false;
} }
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
start(); start();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
running = false; running = false;
} }
private void start() { private void start() {
loadThread = new Thread(new Runnable() { loadThread = new Thread(new Runnable() {
@Override @Override
@ -70,12 +70,12 @@ public class PinnedService extends Service {
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
while (running) { while (running) {
doUpdates(); doUpdates();
long timeout = activityInForeground ? FOREGROUND_INTERVAL : BACKGROUND_INTERVAL; long timeout = activityInForeground ? FOREGROUND_INTERVAL : BACKGROUND_INTERVAL;
try { try {
Thread.sleep(timeout); Thread.sleep(timeout);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -84,17 +84,17 @@ public class PinnedService extends Service {
} }
} }
}); });
loadThread.start(); loadThread.start();
} }
private void doUpdates() { private void doUpdates() {
List<Pin> pins = PinnedManager.getInstance().getPins(); List<Pin> pins = PinnedManager.getInstance().getPins();
for (Pin pin : pins) { for (Pin pin : pins) {
pin.updateWatch(); pin.updateWatch();
} }
} }
public static void callOnPinsChanged() { public static void callOnPinsChanged() {
new Handler(Looper.getMainLooper()).post(new Runnable() { new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override @Override
@ -103,20 +103,20 @@ public class PinnedService extends Service {
} }
}); });
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void showNotification(String text) { private void showNotification(String text) {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this); Notification.Builder builder = new Notification.Builder(this);
builder.setTicker(text); builder.setTicker(text);
builder.setContentTitle(text); builder.setContentTitle(text);
builder.setContentText(text); builder.setContentText(text);
builder.setSmallIcon(R.drawable.ic_stat_notify); builder.setSmallIcon(R.drawable.ic_stat_notify);
nm.notify(1, builder.getNotification()); nm.notify(1, builder.getNotification());
} }
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return null; return null;

Loading…
Cancel
Save