EvernoteClient.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package com.epson.iprint.storage.evernote;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.os.AsyncTask;
  5. import com.epson.iprint.storage.StorageItem;
  6. import com.epson.iprint.storage.StorageServiceClient;
  7. import com.epson.iprint.storage.evernote.EvernoteRequest;
  8. import epson.print.CommonDefine;
  9. import epson.print.Util.AsyncTaskExecutor;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import org.apache.commons.lang.CharEncoding;
  13. public class EvernoteClient extends StorageServiceClient {
  14. public String getStorageServiceName(Context context) {
  15. return "Evernote";
  16. }
  17. public boolean isSupportedUploadType(StorageServiceClient.UploadFileType uploadFileType) {
  18. return true;
  19. }
  20. public boolean isSignedIn(Context context) {
  21. return epson.server.service.EvernoteClient.getEvernoteSession(context).isLoggedIn();
  22. }
  23. public boolean revokeSignedInData(Activity activity) {
  24. epson.server.service.EvernoteClient.logout(activity);
  25. return true;
  26. }
  27. public boolean isValidUploadName(String str) {
  28. if (str.startsWith(CommonDefine.DOT)) {
  29. return false;
  30. }
  31. try {
  32. if (str.getBytes(CharEncoding.UTF_8).length > 256) {
  33. return false;
  34. }
  35. for (char indexOf : str.toCharArray()) {
  36. if ("\\/:,;*?<>|#、\"".indexOf(indexOf) > -1) {
  37. return false;
  38. }
  39. }
  40. return super.isValidUploadName(str);
  41. } catch (Exception unused) {
  42. return false;
  43. }
  44. }
  45. public StorageServiceClient.Uploader getUploader(final Context context, StorageServiceClient.UploadFileType uploadFileType, final String str, final String str2) {
  46. return new StorageServiceClient.Uploader() {
  47. EvernoteRequest request = new EvernoteRequest(context);
  48. StorageServiceClient.UploadCompletion uploaded;
  49. EvernoteRequest.UploadHandler uploader = this.request.getUploadHandler();
  50. public boolean isCancelable() {
  51. return false;
  52. }
  53. /* renamed from: com.epson.iprint.storage.evernote.EvernoteClient$1$UploadTask */
  54. class UploadTask extends AsyncTaskExecutor<Void, Void, Void> {
  55. UploadTask() {
  56. }
  57. protected Void doInBackground(Void... voidArr) {
  58. StorageServiceClient.ProcessError processError;
  59. StorageServiceClient.ProcessError processError2 = StorageServiceClient.ProcessError.NONE;
  60. do {
  61. try {
  62. StorageItem uploadFolder = C09441.this.request.getUploadFolder();
  63. if (uploadFolder == null) {
  64. uploadFolder = C09441.this.request.newUploadFolder();
  65. }
  66. processError = C09441.this.uploader.upload(uploadFolder, str, str2);
  67. } catch (Exception e) {
  68. processError = C09441.this.request.handleException(e);
  69. }
  70. } while (StorageServiceClient.ProcessError.RETRY.equals(processError));
  71. C09441.this.uploaded.onUploadComplete(str, str2, processError);
  72. return null;
  73. }
  74. }
  75. public void start(StorageServiceClient.UploadCompletion uploadCompletion) {
  76. this.uploaded = uploadCompletion;
  77. new UploadTask().executeOnExecutor(new Void[0]);
  78. }
  79. public void cancel() {
  80. this.uploader.cancel();
  81. }
  82. };
  83. }
  84. public StorageServiceClient.Downloader getDownloader(final Context context, final StorageItem storageItem, final String str) {
  85. return new StorageServiceClient.Downloader() {
  86. StorageServiceClient.DownloadCompletion downloaded;
  87. EvernoteRequest.DownloadHandler downloader = this.request.getDownloadHandler();
  88. EvernoteRequest request = new EvernoteRequest(context);
  89. public boolean isCancelable() {
  90. return true;
  91. }
  92. /* renamed from: com.epson.iprint.storage.evernote.EvernoteClient$2$DownloadTask */
  93. class DownloadTask extends AsyncTask<Void, Void, Void> {
  94. DownloadTask() {
  95. }
  96. protected Void doInBackground(Void... voidArr) {
  97. StorageServiceClient.ProcessError processError;
  98. StorageServiceClient.ProcessError processError2 = StorageServiceClient.ProcessError.NONE;
  99. do {
  100. try {
  101. processError = C09452.this.downloader.download(storageItem.path, str);
  102. } catch (Exception e) {
  103. processError = C09452.this.request.handleException(e);
  104. }
  105. } while (StorageServiceClient.ProcessError.RETRY.equals(processError));
  106. C09452.this.downloaded.onDownloadComplete(storageItem, str, processError);
  107. return null;
  108. }
  109. }
  110. public void start(StorageServiceClient.DownloadCompletion downloadCompletion) {
  111. this.downloaded = downloadCompletion;
  112. new DownloadTask().execute(new Void[0]);
  113. }
  114. public void cancel() {
  115. this.downloader.cancel();
  116. }
  117. };
  118. }
  119. public StorageServiceClient.Enumerator getEnumerator(final Context context) {
  120. return new StorageServiceClient.Enumerator() {
  121. StorageServiceClient.EnumerateCompletion enumerated;
  122. EvernoteRequest request = new EvernoteRequest(context);
  123. private List<StorageItem> getPrintableItems(List<StorageItem> list) {
  124. ArrayList arrayList = new ArrayList();
  125. for (StorageItem next : list) {
  126. if (next.type != StorageItem.ItemType.FILE || EvernoteClient.this.isPrintableFileTypes(next)) {
  127. arrayList.add(next);
  128. }
  129. }
  130. return arrayList;
  131. }
  132. /* renamed from: com.epson.iprint.storage.evernote.EvernoteClient$3$EnumerateTask */
  133. class EnumerateTask extends AsyncTask<StorageItem, Void, Void> {
  134. EnumerateTask() {
  135. }
  136. protected Void doInBackground(StorageItem... storageItemArr) {
  137. StorageServiceClient.ProcessError processError;
  138. StorageServiceClient.ProcessError processError2 = StorageServiceClient.ProcessError.NONE;
  139. StorageItem storageItem = storageItemArr[0];
  140. List<StorageItem> list = null;
  141. do {
  142. try {
  143. processError = StorageServiceClient.ProcessError.NONE;
  144. list = C09463.this.request.getItemList(storageItem);
  145. } catch (Exception e) {
  146. processError = C09463.this.request.handleException(e);
  147. }
  148. } while (StorageServiceClient.ProcessError.RETRY.equals(processError));
  149. if (list != null) {
  150. list = C09463.this.getPrintableItems(list);
  151. } else {
  152. processError = StorageServiceClient.ProcessError.ERROR;
  153. }
  154. C09463.this.enumerated.onEnumerateComplete(list, processError);
  155. return null;
  156. }
  157. }
  158. public StorageItem getRootItem() {
  159. return this.request.getFeedItem();
  160. }
  161. public void enumerate(StorageItem storageItem, StorageServiceClient.EnumerateCompletion enumerateCompletion) {
  162. this.enumerated = enumerateCompletion;
  163. new EnumerateTask().execute(new StorageItem[]{storageItem});
  164. }
  165. };
  166. }
  167. }