Browse files

Merge branch 'dev' into feature_cambutton

Conflicts:
	up666/src/org/qless/up666/UploadActivity.java

feature_cambutton had some changes in a part, that is no longer needed.
this pars has been replaced by the newer code.
  • Loading branch information...
2 parents e8d073a + 4d4a834 commit f3c67412c462622b34610eef86407a5db867506a @qorron committed Oct 18, 2011
Showing with 144 additions and 116 deletions.
  1. +3 −1 up666/res/values-de/strings.xml
  2. +2 −0 up666/res/values/strings.xml
  3. +139 −115 up666/src/org/qless/up666/UploadActivity.java
View
4 up666/res/values-de/strings.xml
@@ -21,9 +21,11 @@
<string name="errorMessageFileNotFound">Die angegebene Datei konnte nicht gefunden werden bzw. der Zugriff darauf wurde verweigert.</string>
<string name="errorTitleBadURL">Unverständliche Antwort</string>
<string name="errorMessageBadURL">Die Antwort von 666kb.com enthielt keine Bilder-URL. Möglicherweise ist das Bild nicht in Ordnung (666kb.com unterstützt nur: png, jpeg und gif) oder die Webseite wurde verändert. Falls dieser Fehler wiederholt bei mehreren Dateien auftritt kannst du hier einen Fehlerbericht senden.\n\nFehlerbericht jetzt senden?</string>
-
+ <string name="errorTitleBadIntent">Falscher Aufruf</string>
+ <string name="errorMessageBadIntent">Die Anwendung konnte den Aurfur nicht verstehen.</string>
<string name="errorTitle">Unerwarteter Fehler</string>
<string name="errorMessage">Irgendetwas lief schief. Wenn der Fehler weiterhin besteht kannst du helfen den Fehler zu beheben, indem du einen Fehlerbericht sendest.\n\nFehlerbericht jetzt senden?</string>
+
<string name="errorSendAction">Fehlerbericht senden...</string>
<string name="errorSubject">Fehlerbericht</string>
</resources>
View
2 up666/res/values/strings.xml
@@ -23,6 +23,8 @@
<string name="errorMessageFileNotFound">The requested file could not be found.</string>
<string name="errorTitleBadURL">Bad reply</string>
<string name="errorMessageBadURL">The reply 666kb sent did not contain an image URL. There may be something wrong with the image (666kb supports only png, jpeg and gif) or the site has been changed.\n\nSend an error report?</string>
+ <string name="errorTitleBadIntent">Wrong call format</string>
+ <string name="errorMessageBadIntent">The app was called in a way it could not understand.</string>
<string name="errorTitle">Unexpected Error</string>
<string name="errorMessage">Something went wrong. Please, just try again and if the error persists you could help me fix it by sending me an error report.\n\nSend an error report now?</string>
View
254 up666/src/org/qless/up666/UploadActivity.java
@@ -51,7 +51,7 @@
/**
* @author quattro
*
- * This activity handles the send intent for images.
+ * This activity handles the send intent for images.
*
*/
public class UploadActivity extends Activity {
@@ -68,9 +68,11 @@
private Exception ex;
private Error error;
+ private String mimeType;
+ private String filePath;
public enum Error {
- FILE_NOT_FOUND, HOST_NOT_FOUND, NETWORK, BAD_URL
+ FILE_NOT_FOUND, HOST_NOT_FOUND, NETWORK, BAD_URL, BAD_INTENT
}
/*
@@ -81,9 +83,13 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Log.d("ullilog", "start");
+
+ if (savedInstanceState != null) {
+ imageURL = savedInstanceState.getString("imageURL");
+ filePath = savedInstanceState.getString("filePath");
+ mimeType = savedInstanceState.getString("mimeType");
+ }
Intent intent = getIntent();
- Log.d("ullilog", "got intent");
setContentView(R.layout.upload);
mGreeting = (TextView) findViewById(R.id.hello);
@@ -128,127 +134,67 @@ public void onClick(View v) {
});
- Log.d("ullilog", "about to proccess intent");
-
- if (Intent.ACTION_SEND.equals(intent.getAction())) {
- Bundle extras = intent.getExtras();
- if (extras.containsKey(Intent.EXTRA_STREAM)) {
- Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
- String scheme = uri.getScheme();
- Log.d("ullilog", "content scheme is: " + scheme);
- boolean ok = false;
- String mimeType = null;
- String filePath = null;
- if (scheme.equals("content")) {
- mimeType = intent.getType();
- ContentResolver contentResolver = getContentResolver();
- Cursor cursor = contentResolver.query(uri, null, null,
- null, null);
- cursor.moveToFirst();
- filePath = cursor.getString(cursor
- .getColumnIndexOrThrow(Images.Media.DATA));
- ok = true;
- } else if (scheme.equals("file")) {
- mimeType = intent.getType();
- filePath = uri.getPath();
- ok = true;
+ if (imageURL == null) {
+ // since there is no previously stored url, we have to upload the file
+ if (Intent.ACTION_SEND.equals(intent.getAction())) {
+ Bundle extras = intent.getExtras();
+ if (extras.containsKey(Intent.EXTRA_STREAM)) {
+ Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
+ String scheme = uri.getScheme();
+ boolean ok = false;
+ mimeType = null;
+ filePath = null;
+ if (scheme.equals("content")) {
+ mimeType = intent.getType();
+ ContentResolver contentResolver = getContentResolver();
+ Cursor cursor = contentResolver.query(uri, null, null,
+ null, null);
+ cursor.moveToFirst();
+ filePath = cursor.getString(cursor
+ .getColumnIndexOrThrow(Images.Media.DATA));
+ ok = true;
+ } else if (scheme.equals("file")) {
+ mimeType = intent.getType();
+ filePath = uri.getPath();
+ ok = true;
+ } else {
+ Log.d("BAD_INTENT", "no content scheme, is: " + scheme);
+ errorDialogue(null, Error.BAD_INTENT);
+ }
+ if (ok) {
+ mMimeTypeTextView.setText(mimeType);
+ mFilePathTextView.setText(filePath);
+ new ImageUploadTask().execute(filePath);
+ }
} else {
- Log.d("ullilog", "no content scheme, is: " + scheme);
- Context context = getApplicationContext();
- CharSequence text = "no content scheme";
- int duration = Toast.LENGTH_SHORT;
- Toast toast = Toast.makeText(context, text, duration);
- toast.show();
- }
- if (ok) {
- mMimeTypeTextView.setText(mimeType);
- mFilePathTextView.setText(filePath);
- new ImageUploadTask().execute(filePath);
+ Log.d("BAD_INTENT", "no EXTRA_STREAM");
+ errorDialogue(null, Error.BAD_INTENT);
}
} else {
- Log.d("ullilog", "no EXTRA_STREAM");
- Context context = getApplicationContext();
- CharSequence text = "no EXTRA_STREAM";
- int duration = Toast.LENGTH_SHORT;
- Toast toast = Toast.makeText(context, text, duration);
- toast.show();
+ Log.d("BAD_INTENT", "no ACTION_SEND");
+ errorDialogue(null, Error.BAD_INTENT);
}
} else {
- String action = intent.getAction();
- Log.d("ullilog", "no ACTION_SEND "+action);
- Context context = getApplicationContext();
- CharSequence text = "no ACTION_SEND "+action;
- int duration = Toast.LENGTH_SHORT;
- Toast toast = Toast.makeText(context, text, duration);
- toast.show();
+ // we already have a url, so we just update the gui and make it look like expected.
+ resetGUI();
}
+
}
- /**
- * @author quattro
- *
- * handles the resize and upload process in a background thread
+ /*
+ * (non-Javadoc)
*
+ * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
*/
- private class ImageUploadTask extends AsyncTask<String, Integer, URL> {
-
- private Exception ex;
- private Error error;
-
- /*
- * (non-Javadoc)
- *
- * @see android.os.AsyncTask#onPreExecute()
- */
- @Override
- protected void onPreExecute() {
- mProgress.setVisibility(ProgressBar.VISIBLE);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see android.os.AsyncTask#doInBackground(Params[])
- */
- @Override
- protected URL doInBackground(String... params) {
- URL url = null;
- try {
- url = ImageUploader.upload(params[0]);
- } catch (FileNotFoundException e) {
- error = Error.FILE_NOT_FOUND;
- } catch (UnknownHostException e) {
- error = Error.HOST_NOT_FOUND;
- } catch (MalformedURLException e) {
- error = Error.BAD_URL;
- ex = e;
- } catch (ProtocolException e) {
- ex = e;
- } catch (IOException e) {
- error = Error.NETWORK;
- } catch (Exception e) {
- ex = e;
- }
- return url;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
- */
- @Override
- protected void onPostExecute(URL result) {
- mProgress.setVisibility(ProgressBar.INVISIBLE);
- if (ex != null || error != null) {
- errorDialogue(ex, error);
- } else {
- showURL(result);
- }
- }
-
+ protected void onSaveInstanceState(Bundle outState) {
+ outState.putString("imageURL", imageURL);
+ outState.putString("mimeType", mimeType);
+ outState.putString("filePath", filePath);
}
+
+
+
/**
* Displays the image URL and enables the copy/share buttons
*
@@ -293,6 +239,10 @@ protected void errorDialogue(Exception ex, Error error) {
b.setTitle(R.string.errorTitleBadURL);
b.setMessage(R.string.errorMessageBadURL);
break;
+ case BAD_INTENT:
+ b.setTitle(R.string.errorTitleBadIntent);
+ b.setMessage(R.string.errorMessageBadIntent);
+ break;
default:
b.setTitle(R.string.errorTitle);
b.setMessage(R.string.errorMessage);
@@ -323,7 +273,7 @@ private void sendError() {
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
String stacktrace = sw.toString();
-
+
// create an email intent to send to yourself
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
@@ -334,11 +284,85 @@ private void sendError() {
getString(R.string.app_name) + " "
+ getString(R.string.errorSubject));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, stacktrace);
-
+
// start the email activity - note you need to start it
// with a chooser
startActivity(Intent.createChooser(emailIntent,
getString(R.string.errorSendAction)));
+
+ }
+ private void resetGUI () {
+ mProgress.setVisibility(ProgressBar.INVISIBLE);
+ mMimeTypeTextView.setText(mimeType);
+ mFilePathTextView.setText(filePath);
+ mImageURLTextView.setText(imageURL);
+ mCopyButton.setEnabled(true);
+ mShareButton.setEnabled(true);
+ }
+
+ /**
+ * @author quattro
+ *
+ * handles the resize and upload process in a background thread
+ *
+ */
+ private class ImageUploadTask extends AsyncTask<String, Integer, URL> {
+
+ private Exception ex;
+ private Error error;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see android.os.AsyncTask#onPreExecute()
+ */
+ @Override
+ protected void onPreExecute() {
+ mProgress.setVisibility(ProgressBar.VISIBLE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see android.os.AsyncTask#doInBackground(Params[])
+ */
+ @Override
+ protected URL doInBackground(String... params) {
+ URL url = null;
+ try {
+ url = ImageUploader.upload(params[0]);
+ } catch (FileNotFoundException e) {
+ error = Error.FILE_NOT_FOUND;
+ } catch (UnknownHostException e) {
+ error = Error.HOST_NOT_FOUND;
+ } catch (MalformedURLException e) {
+ error = Error.BAD_URL;
+ ex = e;
+ } catch (ProtocolException e) {
+ ex = e;
+ } catch (IOException e) {
+ error = Error.NETWORK;
+ } catch (Exception e) {
+ ex = e;
+ }
+ return url;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
+ */
+ @Override
+ protected void onPostExecute(URL result) {
+ mProgress.setVisibility(ProgressBar.INVISIBLE);
+ if (ex != null || error != null) {
+ errorDialogue(ex, error);
+ } else {
+ showURL(result);
+ }
+ }
+
}
}

0 comments on commit f3c6741

Please sign in to comment.