use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.
the class MultimediaCardEditorActivity method save.
private void save() {
NoteService.saveMedia((MultimediaEditableNote) mNote);
NoteService.updateJsonNoteFromMultimediaNote(mNote, mEditorNote);
TaskListener listener = new TaskListener() {
@Override
public void onProgressUpdate(TaskData... values) {
// TODO Auto-generated method stub
}
@Override
public void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
public void onPostExecute(TaskData result) {
// TODO Auto-generated method stub
}
};
if (mAddNote) {
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, listener, new DeckTask.TaskData(mEditorNote));
} else {
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, listener, new DeckTask.TaskData(mCol.getSched(), mCard, false));
}
setResult(Activity.RESULT_OK);
finish();
animateRight();
}
use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.
the class Models method fieldMap.
/** "Mapping of field name -> (ord, field). */
public Map<String, Pair<Integer, JSONObject>> fieldMap(JSONObject m) {
JSONArray ja;
try {
ja = m.getJSONArray("flds");
// TreeMap<Integer, String> map = new TreeMap<Integer, String>();
Map<String, Pair<Integer, JSONObject>> result = new HashMap<String, Pair<Integer, JSONObject>>();
for (int i = 0; i < ja.length(); i++) {
JSONObject f = ja.getJSONObject(i);
result.put(f.getString("name"), new Pair<Integer, JSONObject>(f.getInt("ord"), f));
}
return result;
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundSearchCards.
private TaskData doInBackgroundSearchCards(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundSearchCards");
Collection col = (Collection) params[0].getObjArray()[0];
HashMap<String, String> deckNames = (HashMap<String, String>) params[0].getObjArray()[1];
String query = (String) params[0].getObjArray()[2];
String order = (String) params[0].getObjArray()[3];
TaskData result = new TaskData(col.findCardsForCardBrowser(query, order, deckNames));
if (DeckTask.taskIsCancelled()) {
return null;
} else {
publishProgress(result);
}
return new TaskData(col.cardCount(col.getDecks().allIds()));
}
use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.
the class Feedback method postFeedback.
/**
* Posting feedback or error info to the server. This is called from the AsyncTask.
*
* @param url The url to post the feedback to.
* @param type The type of the info, eg Feedback.TYPE_CRASH_STACKTRACE.
* @param feedback For feedback types this is the message. For error/crash types this is the path to the error file.
* @param groupId A single time generated ID, so that errors/feedback send together can be grouped together.
* @param index The index of the error in the list
* @return A Payload file showing success, response code and response message.
*/
public static Payload postFeedback(String url, String type, String feedback, String groupId, int index, Application app) {
Payload result = new Payload(null);
List<NameValuePair> pairs = null;
if (!isErrorType(type)) {
pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("type", type));
pairs.add(new BasicNameValuePair("groupid", groupId));
pairs.add(new BasicNameValuePair("index", "0"));
pairs.add(new BasicNameValuePair("message", feedback));
addTimestamp(pairs);
} else {
pairs = Feedback.extractPairsFromError(type, feedback, groupId, index, app);
if (pairs == null) {
result.success = false;
result.result = null;
}
}
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("User-Agent", "AnkiDroid");
try {
httpPost.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = httpClient.execute(httpPost);
Log.e(AnkiDroidApp.TAG, String.format("Bug report posted to %s", url));
int respCode = response.getStatusLine().getStatusCode();
switch(respCode) {
case 200:
result.success = true;
result.returnType = respCode;
result.result = Utils.convertStreamToString(response.getEntity().getContent());
Log.i(AnkiDroidApp.TAG, String.format("postFeedback OK: %s", result.result));
break;
default:
Log.e(AnkiDroidApp.TAG, String.format("postFeedback failure: %d - %s", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
result.success = false;
result.returnType = respCode;
result.result = response.getStatusLine().getReasonPhrase();
break;
}
} catch (ClientProtocolException ex) {
Log.e(AnkiDroidApp.TAG, "ClientProtocolException: " + ex.toString());
result.success = false;
result.result = ex.toString();
} catch (IOException ex) {
Log.e(AnkiDroidApp.TAG, "IOException: " + ex.toString());
result.success = false;
result.result = ex.toString();
}
return result;
}
use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.
the class Feedback method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
Themes.applyTheme(this);
super.onCreate(savedInstanceState);
Resources res = getResources();
Context context = getBaseContext();
SharedPreferences sharedPreferences = AnkiDroidApp.getSharedPrefs(context);
mReportErrorMode = sharedPreferences.getString("reportErrorMode", REPORT_ASK);
mNonce = UUID.randomUUID().getMostSignificantBits();
mFeedbackUrl = res.getString(R.string.feedback_post_url);
mErrorUrl = res.getString(R.string.error_post_url);
mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mPostingFeedback = false;
initAllAlertDialogs();
getErrorFiles();
Intent i = getIntent();
mAllowFeedback = (i.hasExtra("request") && (i.getIntExtra("request", 0) == DeckPicker.REPORT_FEEDBACK || i.getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR)) || mReportErrorMode.equals(REPORT_ASK);
if (!mAllowFeedback) {
if (mReportErrorMode.equals(REPORT_ALWAYS)) {
// Always report
try {
String feedback = "Automatically sent";
Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl, feedback, mErrorReports, mNonce, getApplication(), true }));
if (mErrorReports.size() > 0) {
mPostingFeedback = true;
}
if (feedback.length() > 0) {
mPostingFeedback = true;
}
} catch (Exception e) {
Log.e(AnkiDroidApp.TAG, e.toString());
}
finish();
if (AnkiDroidApp.SDK_VERSION > 4) {
ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
}
return;
} else if (mReportErrorMode.equals(REPORT_NEVER)) {
// Never report
deleteFiles(false, false);
finish();
if (AnkiDroidApp.SDK_VERSION > 4) {
ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
}
return;
}
}
View mainView = getLayoutInflater().inflate(R.layout.feedback, null);
setContentView(mainView);
Themes.setWallpaper(mainView);
Themes.setTextViewStyle(findViewById(R.id.tvFeedbackDisclaimer));
Themes.setTextViewStyle(findViewById(R.id.lvFeedbackErrorList));
Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
mEtFeedbackText = (EditText) findViewById(R.id.etFeedbackText);
mLvErrorList = (ListView) findViewById(R.id.lvFeedbackErrorList);
mErrorAdapter = new SimpleAdapter(this, mErrorReports, R.layout.error_item, new String[] { "name", "state", "result" }, new int[] { R.id.error_item_text, R.id.error_item_progress, R.id.error_item_status });
mErrorAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object arg1, String text) {
switch(view.getId()) {
case R.id.error_item_progress:
if (text.equals(STATE_UPLOADING)) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
return true;
case R.id.error_item_status:
if (text.length() == 0) {
view.setVisibility(View.GONE);
return true;
} else {
view.setVisibility(View.VISIBLE);
return false;
}
}
return false;
}
});
btnClearAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
deleteFiles(false, false);
refreshErrorListView();
refreshInterface();
}
});
mLvErrorList.setAdapter(mErrorAdapter);
btnSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mPostingFeedback) {
String feedback = mEtFeedbackText.getText().toString();
Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl, feedback, mErrorReports, mNonce, getApplication(), false }));
if (mErrorReports.size() > 0) {
mPostingFeedback = true;
}
if (feedback.length() > 0) {
mPostingFeedback = true;
}
refreshInterface();
}
}
});
btnKeepLatest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
deleteFiles(false, true);
refreshErrorListView();
refreshInterface();
}
});
refreshInterface();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
Aggregations