private WeakReference<ProgressDialog> mSavingProgressDialog;
private static final int SEEK_BAR_MAX = 600;
- private LightCycleChecker mCheckFor360;
+ private LoadBitmapTask mLoadBitmapTask;
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
- String data = intent.getDataString();
- if (data != null) {
- Uri uri = Uri.parse(data);
- mImageLoader.loadBitmap(uri, getScreenImageSize());
-
- View tinyPlanetView = listColors.findViewById(R.id.tinyplanetButton);
- if (tinyPlanetView != null) {
- tinyPlanetView.setVisibility(View.GONE);
- mCheckFor360 = new LightCycleChecker(tinyPlanetView);
- mCheckFor360.execute();
- }
+ if (intent.getData() != null) {
+ startLoadBitmap(intent.getData());
} else {
pickImage();
}
}
}
- private class LightCycleChecker extends AsyncTask<Void, Void, Boolean> {
+ private void startLoadBitmap(Uri uri) {
+ View tinyPlanetView = findViewById(R.id.tinyplanetButton);
+ if (tinyPlanetView != null) {
+ tinyPlanetView.setVisibility(View.GONE);
+ }
+ mLoadBitmapTask = new LoadBitmapTask(tinyPlanetView);
+ mLoadBitmapTask.execute(uri);
+ }
+
+ private class LoadBitmapTask extends AsyncTask<Uri, Void, Boolean> {
View mTinyPlanetButton;
+ int mBitmapSize;
- public LightCycleChecker(View button) {
+ public LoadBitmapTask(View button) {
mTinyPlanetButton = button;
+ mBitmapSize = getScreenImageSize();
}
@Override
- protected Boolean doInBackground(Void... params) {
+ protected Boolean doInBackground(Uri... params) {
+ mImageLoader.loadBitmap(params[0], mBitmapSize);
return mImageLoader.queryLightCycle360();
}
if (result) {
mTinyPlanetButton.setVisibility(View.VISIBLE);
}
- mCheckFor360 = null;
+ mLoadBitmapTask = null;
super.onPostExecute(result);
}
@Override
protected void onDestroy() {
- if (mCheckFor360 != null) {
- mCheckFor360.cancel(false);
+ if (mLoadBitmapTask != null) {
+ mLoadBitmapTask.cancel(false);
}
super.onDestroy();
}
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
- mImageLoader.loadBitmap(selectedImageUri, getScreenImageSize());
+ startLoadBitmap(selectedImageUri);
}
}
}
}
}
- public void warnListeners() {
- for (int i = 0; i < mListeners.size(); i++) {
- ImageShow imageShow = mListeners.elementAt(i);
- imageShow.updateImage();
- }
+ private void warnListeners() {
+ mActivity.runOnUiThread(mWarnListenersRunnable);
}
+ private Runnable mWarnListenersRunnable = new Runnable() {
+
+ @Override
+ public void run() {
+ for (int i = 0; i < mListeners.size(); i++) {
+ ImageShow imageShow = mListeners.elementAt(i);
+ imageShow.updateImage();
+ imageShow.invalidate();
+ }
+ }
+ };
+
// TODO: this currently does the loading + filtering on the UI thread -- need to
// move this to a background thread.
public Bitmap getScaleOneImageForPreset(ImageShow caller, ImagePreset imagePreset, Rect bounds,
int outputSize = Math.min(w, h);
ImagePreset preset = getImagePreset();
- if (preset != null) {
- if (preset.isPanoramaSafe()) {
- try {
- XMPMeta xmp = preset.getImageLoader().getXmpObject();
- int croppedAreaWidth =
- getInt(xmp, CROPPED_AREA_IMAGE_WIDTH_PIXELS);
- int croppedAreaHeight =
- getInt(xmp, CROPPED_AREA_IMAGE_HEIGHT_PIXELS);
- int fullPanoWidth =
- getInt(xmp, CROPPED_AREA_FULL_PANO_WIDTH_PIXELS);
- int fullPanoHeight =
- getInt(xmp, CROPPED_AREA_FULL_PANO_HEIGHT_PIXELS);
- int left = getInt(xmp, CROPPED_AREA_LEFT);
- int top = getInt(xmp, CROPPED_AREA_TOP);
-
- Bitmap paddedBitmap = Bitmap.createBitmap(
- fullPanoWidth, fullPanoHeight, Bitmap.Config.ARGB_8888);
- Canvas paddedCanvas = new Canvas(paddedBitmap);
-
- int right = left + croppedAreaWidth;
- int bottom = top + croppedAreaHeight;
- Rect destRect = new Rect(left, top, right, bottom);
- paddedCanvas.drawBitmap(bitmapIn, null, destRect, null);
- bitmapIn = paddedBitmap;
- } catch (XMPException ex) {
- // Do nothing, just use bitmapIn as is.
- }
- } else {
- // Do nothing, just use bitmapIn as is, there is nothing else we
- // can do.
- }
+ if (preset != null && preset.isPanoramaSafe()) {
+ bitmapIn = applyXmp(bitmapIn, preset);
}
Bitmap mBitmapOut = Bitmap.createBitmap(
return mBitmapOut;
}
+ private Bitmap applyXmp(Bitmap bitmapIn, ImagePreset preset) {
+ try {
+ XMPMeta xmp = preset.getImageLoader().getXmpObject();
+ if (xmp == null) {
+ // Do nothing, just use bitmapIn as is.
+ return bitmapIn;
+ }
+ int croppedAreaWidth =
+ getInt(xmp, CROPPED_AREA_IMAGE_WIDTH_PIXELS);
+ int croppedAreaHeight =
+ getInt(xmp, CROPPED_AREA_IMAGE_HEIGHT_PIXELS);
+ int fullPanoWidth =
+ getInt(xmp, CROPPED_AREA_FULL_PANO_WIDTH_PIXELS);
+ int fullPanoHeight =
+ getInt(xmp, CROPPED_AREA_FULL_PANO_HEIGHT_PIXELS);
+ int left = getInt(xmp, CROPPED_AREA_LEFT);
+ int top = getInt(xmp, CROPPED_AREA_TOP);
+
+ Bitmap paddedBitmap = Bitmap.createBitmap(
+ fullPanoWidth, fullPanoHeight, Bitmap.Config.ARGB_8888);
+ Canvas paddedCanvas = new Canvas(paddedBitmap);
+
+ int right = left + croppedAreaWidth;
+ int bottom = top + croppedAreaHeight;
+ Rect destRect = new Rect(left, top, right, bottom);
+ paddedCanvas.drawBitmap(bitmapIn, null, destRect, null);
+ bitmapIn = paddedBitmap;
+ } catch (XMPException ex) {
+ // Do nothing, just use bitmapIn as is.
+ }
+ return bitmapIn;
+ }
+
private static int getInt(XMPMeta xmp, String key) throws XMPException {
if (xmp.doesPropertyExist(GOOGLE_PANO_NAMESPACE, key)) {
return xmp.getPropertyInteger(GOOGLE_PANO_NAMESPACE, key);