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 static final boolean DEVELOPER_MODE = true;
private static ChanApplication instance;
private static RequestQueue volleyRequestQueue;
private static ImageLoader imageLoader;
public ChanApplication() {
instance = this;
}
public static ChanApplication getInstance() {
return instance;
}
public static RequestQueue getVolleyRequestQueue() {
return volleyRequestQueue;
}
public static ImageLoader getImageLoader() {
return imageLoader;
}
public static SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(instance);
}
@Override
public void onCreate() {
super.onCreate();
if (ChanApplication.DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
}
IconCache.createIcons(this);
volleyRequestQueue = Volley.newRequestQueue(this);
imageLoader = new ImageLoader(volleyRequestQueue, new BitmapLruImageCache(1024 * 1024 * 8));
new DatabaseManager(this);
new BoardManager(this);
new PinnedManager(this);
new ReplyManager(this);
// startService(new Intent(this, PinnedService.class));
}
}

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

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

Loading…
Cancel
Save