StorageServer.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package epson.server.screens;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.os.AsyncTask;
  8. import android.os.Build;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import com.epson.iprint.storage.StorageProcessActivity;
  12. import com.epson.iprint.storage.StorageProcessDownloadActivity;
  13. import com.epson.iprint.storage.StorageServiceClient;
  14. import com.epson.iprint.storage.gdrivev3.ListAndDownloadActivity;
  15. import com.epson.iprint.storage.onedrive.OneDriveStorageProcessUploadActivity;
  16. import java.util.ArrayList;
  17. import epson.common.ExternalFileUtils;
  18. import epson.print.ActivityIACommon;
  19. import epson.print.ActivityRequestPermissions;
  20. import epson.print.CommonDefine;
  21. import epson.print.R;
  22. import epson.print.SimpleMessageDialogFragment;
  23. import epson.print.Util.EPLog;
  24. import epson.print.Util.Utils;
  25. import epson.print.screen.WorkingDialog;
  26. import epson.server.utils.Define;
  27. import epson.server.utils.MyUtility;
  28. public class StorageServer extends ActivityIACommon implements CommonDefine {
  29. public static final String FOR_PRINT_LOGGER_CALL_FROM = "forLoggerCallFrom";
  30. public static final int FOR_PRINT_LOGGER_CALL_FROM_NO_INFO = 0;
  31. public static final int FOR_PRINT_LOGGER_CALL_FROM_SCAN = 1;
  32. private static final int REQEST_RUNTIMEPERMMISSION = 1;
  33. int mNumOfFiles;
  34. boolean mScanSaveAction = false;
  35. private ArrayList<String> mScanedFilePath = new ArrayList<>();
  36. public void onCreate(Bundle bundle) {
  37. super.onCreate(bundle);
  38. setContentView(R.layout.choose_storage_server);
  39. setActionBar(R.string.network_storage_title, true);
  40. new AsyncTask<Void, Void, Boolean>() {
  41. WorkingDialog workingDialog = new WorkingDialog(StorageServer.this);
  42. protected void onPreExecute() {
  43. super.onPreExecute();
  44. workingDialog.show();
  45. }
  46. protected Boolean doInBackground(Void... voidArr) {
  47. if (!Utils.getInstance().isNetworkAvailable(StorageServer.this)) {
  48. return false;
  49. }
  50. if (new MyUtility().doNet(StorageServer.this) == "") {
  51. return false;
  52. }
  53. return true;
  54. }
  55. protected void onPostExecute(Boolean bool) {
  56. super.onPostExecute(bool);
  57. workingDialog.dismiss();
  58. StorageServer.this.initStorageItem(bool.booleanValue());
  59. }
  60. }.execute(new Void[0]);
  61. }
  62. protected void onActivityResult(int i, int i2, Intent intent) {
  63. super.onActivityResult(i, i2, intent);
  64. if (i == 1 && i2 == -1) {
  65. saveLocalMemory();
  66. }
  67. }
  68. private void initStorageItem(boolean z) {
  69. if (getIntent().getIntExtra(FOR_PRINT_LOGGER_CALL_FROM, 0) == 1) {
  70. mScanSaveAction = true;
  71. } else {
  72. mScanSaveAction = false;
  73. }
  74. final int intExtra = getIntent().getIntExtra(Define.PICK_SERVER_FOR, 1);
  75. if (!z) {
  76. findViewById(R.id.evernote).setEnabled(false);
  77. findViewById(R.id.google_doc).setEnabled(false);
  78. findViewById(R.id.drop_box).setEnabled(false);
  79. findViewById(R.id.box_net).setEnabled(false);
  80. findViewById(R.id.onedrive).setEnabled(false);
  81. findViewById(R.id.evernote_next).setVisibility(View.GONE);
  82. findViewById(R.id.google_doc_next).setVisibility(View.GONE);
  83. findViewById(R.id.drop_box_next).setVisibility(View.GONE);
  84. findViewById(R.id.box_net_next).setVisibility(View.GONE);
  85. findViewById(R.id.onedrive_next).setVisibility(View.GONE);
  86. new AlertDialog.Builder(this).setCancelable(false).setMessage(getString(R.string.str_no_network)).setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
  87. public void onClick(DialogInterface dialogInterface, int i) {
  88. }
  89. }).show();
  90. }
  91. if (intExtra == 2) {
  92. mScanedFilePath = getIntent().getStringArrayListExtra(Define.SAVING_FILE_PATH);
  93. findViewById(R.id.save_to_local_section).setVisibility(View.VISIBLE);
  94. setTitle(R.string.save_to_title_name);
  95. }
  96. findViewById(R.id.evernote).setOnClickListener(new View.OnClickListener() {
  97. public void onClick(View view) {
  98. boolean z = StorageServer.mScanSaveAction;
  99. switch (intExtra) {
  100. case 1:
  101. StorageServer.this.startActivity (getApplicationContext(), StorageServiceClient.STORAGE_EVERNOTE));
  102. return;
  103. case 2:
  104. Intent processIntent = StorageProcessActivity.getProcessIntent (getBaseContext(), StorageServiceClient.STORAGE_EVERNOTE, StorageProcessActivity.ProcessType.UPLOAD);
  105. processIntent.putStringArrayListExtra(StorageProcessActivity.EXTRA_UPLOADFILE_LIST, StorageServer.mScanedFilePath);
  106. StorageServer.this.startActivity(processIntent);
  107. return;
  108. default:
  109. return;
  110. }
  111. }
  112. });
  113. findViewById(R.id.google_doc).setOnClickListener(new View.OnClickListener() {
  114. public void onClick(View view) {
  115. switch (intExtra) {
  116. case 1:
  117. StorageServer.this.startActivity(new Intent (getApplicationContext(), ListAndDownloadActivity.class));
  118. return;
  119. case 2:
  120. Intent processIntent = StorageProcessActivity.getProcessIntent (getBaseContext(), StorageServiceClient.STORAGE_GOOGLEDRIVE, StorageProcessActivity.ProcessType.UPLOAD);
  121. processIntent.putStringArrayListExtra(StorageProcessActivity.EXTRA_UPLOADFILE_LIST, StorageServer.mScanedFilePath);
  122. StorageServer.this.startActivity(processIntent);
  123. return;
  124. default:
  125. return;
  126. }
  127. }
  128. });
  129. findViewById(R.id.drop_box).setOnClickListener(new View.OnClickListener() {
  130. public void onClick(View view) {
  131. boolean z = StorageServer.mScanSaveAction;
  132. switch (intExtra) {
  133. case 1:
  134. StorageServer.this.startActivity (getApplicationContext(), StorageServiceClient.STORAGE_DROPBOX));
  135. return;
  136. case 2:
  137. Intent processIntent = StorageProcessActivity.getProcessIntent (getBaseContext(), StorageServiceClient.STORAGE_DROPBOX, StorageProcessActivity.ProcessType.UPLOAD);
  138. processIntent.putStringArrayListExtra(StorageProcessActivity.EXTRA_UPLOADFILE_LIST, StorageServer.mScanedFilePath);
  139. StorageServer.this.startActivity(processIntent);
  140. return;
  141. default:
  142. return;
  143. }
  144. }
  145. });
  146. findViewById(R.id.box_net).setOnClickListener(new View.OnClickListener() {
  147. public void onClick(View view) {
  148. if (Build.VERSION.SDK_INT <= 20) {
  149. StorageServer.this.showCannotUseDialog();
  150. return;
  151. }
  152. switch (intExtra) {
  153. case 1:
  154. StorageServer.this.startActivity (getApplicationContext(), StorageServiceClient.STORAGE_BOX));
  155. return;
  156. case 2:
  157. Intent processIntent = StorageProcessActivity.getProcessIntent (getBaseContext(), StorageServiceClient.STORAGE_BOX, StorageProcessActivity.ProcessType.UPLOAD);
  158. processIntent.putStringArrayListExtra(StorageProcessActivity.EXTRA_UPLOADFILE_LIST, StorageServer.mScanedFilePath);
  159. StorageServer.this.startActivity(processIntent);
  160. return;
  161. default:
  162. return;
  163. }
  164. }
  165. });
  166. findViewById(R.id.onedrive).setOnClickListener(new View.OnClickListener() {
  167. public void onClick(View view) {
  168. switch (intExtra) {
  169. case 1:
  170. StorageServer.this.startActivity (getApplicationContext(), StorageServiceClient.STORAGE_ONEDRIVE));
  171. return;
  172. case 2:
  173. Intent processIntent = OneDriveStorageProcessUploadActivity.getProcessIntent (getBaseContext(), StorageServiceClient.STORAGE_ONEDRIVE, StorageProcessActivity.ProcessType.UPLOAD);
  174. processIntent.putStringArrayListExtra(StorageProcessActivity.EXTRA_UPLOADFILE_LIST, StorageServer.mScanedFilePath);
  175. StorageServer.this.startActivity(processIntent);
  176. return;
  177. default:
  178. return;
  179. }
  180. }
  181. });
  182. findViewById(R.id.local_memory).setOnClickListener(new View.OnClickListener() {
  183. public void onClick(View view) {
  184. if (ActivityRequestPermissions.isRuntimePermissionSupported()) {
  185. String[] strArr = {"android.permission.WRITE_EXTERNAL_STORAGE"};
  186. String[] strArr2 = {StorageServer.this.getString(R.string.permission_dialog_title), StorageServer.this.getString(R.string.permission_dialog_title)};
  187. StorageServer storageServer = StorageServer.this;
  188. StorageServer storageServer2 = StorageServer.this;
  189. ActivityRequestPermissions.Permission permission = new ActivityRequestPermissions.Permission(strArr[0], strArr2, new String[]{ActivityRequestPermissions.DialogParameter.setMessage2((Context) storageServer, storageServer.getString(R.string.permission_dialog_message_storage)), ActivityRequestPermissions.DialogParameter.setMessage3A((Context) storageServer2, storageServer2.getString(R.string.permission_dialog_message_storage), StorageServer.this.getString(R.string.permission_function_storage))});
  190. if (!ActivityRequestPermissions.checkPermission(StorageServer.this, strArr)) {
  191. ActivityRequestPermissions.requestPermission((Activity) StorageServer.this, permission, 1);
  192. return;
  193. }
  194. }
  195. StorageServer.this.saveLocalMemory();
  196. }
  197. });
  198. findViewById(R.id.open_in).setOnClickListener(new View.OnClickListener() {
  199. public void onClick(View view) {
  200. boolean z = StorageServer.mScanSaveAction;
  201. Intent intent = new Intent();
  202. intent.putStringArrayListExtra(Define.SAVING_FILE_PATH, StorageServer.mScanedFilePath);
  203. intent.putExtra("for", 6);
  204. intent.setClass (getBaseContext(), UploadScreen.class);
  205. StorageServer.this.startActivity(intent);
  206. }
  207. });
  208. }
  209. private void showCannotUseDialog() {
  210. SimpleMessageDialogFragment.newInstance(R.string.box_button_message).show(getSupportFragmentManager(), "can-not-use-dialog");
  211. }
  212. private void saveLocalMemory() {
  213. Intent intent = new Intent();
  214. intent.putStringArrayListExtra(Define.SAVING_FILE_PATH, mScanedFilePath);
  215. intent.putExtra("for", 7);
  216. intent.setClass(getBaseContext(), UploadScreen.class);
  217. startActivity(intent);
  218. }
  219. protected void onResume() {
  220. super.onResume();
  221. }
  222. protected void onDestroy() {
  223. super.onDestroy();
  224. }
  225. public void onBackPressed() {
  226. super.onBackPressed();
  227. EPLog.i("StorageServer ", "(onBackPressed)");
  228. ExternalFileUtils.getInstance(this).initDownloadDir();
  229. }
  230. }