Ejemplo n.º 1
0
 @Override
 public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
   upgragingInstance = db;
   LCTX.i("Upgrading from version " + oldVersion + " to version " + newVersion);
   try {
     final IDBAdapter oldAdapter = createAdapter(oldVersion);
     final IDBAdapter newAdapter = createAdapter(newVersion);
     switchAdapter(db, oldAdapter, newAdapter);
   } finally {
     upgragingInstance = null;
     LCTX.i("Upgrade finished");
   }
 }
 @Override
 protected Throwable doInBackground(final String... params) {
   LCTX.d("BookLoadTask.doInBackground(): start");
   try {
     final File cached = scheme.loadToCache(intent.getData(), this);
     if (cached != null) {
       m_fileName = cached.getAbsolutePath();
       setProgressDialogMessage(startProgressStringId);
     }
     getView().waitForInitialization();
     documentModel.open(m_fileName, m_password);
     getDocumentController().init(this);
     return null;
   } catch (final MuPdfPasswordException pex) {
     LCTX.i(pex.getMessage());
     return pex;
   } catch (final Exception e) {
     LCTX.e(e.getMessage(), e);
     return e;
   } catch (final Throwable th) {
     LCTX.e("BookLoadTask.doInBackground(): Unexpected error", th);
     return th;
   } finally {
     LCTX.d("BookLoadTask.doInBackground(): finish");
   }
 }
  /**
   * {@inheritDoc}
   *
   * @see org.emdev.ui.AbstractActivityController#afterCreate(android.app.Activity, boolean)
   */
  @Override
  public void afterCreate(final ViewerActivity activity, final boolean recreated) {

    final AppSettings appSettings = AppSettings.current();

    IUIManager.instance.setFullScreenMode(
        activity, getManagedComponent().view.getView(), appSettings.fullScreen);

    createAction(R.id.mainmenu_crop)
        .putValue("view", activity.getManualCropControls())
        .putValue("mode", DocumentViewMode.SINGLE_PAGE);
    createAction(R.id.mainmenu_zoom).putValue("view", activity.getZoomControls());
    createAction(R.id.mainmenu_search).putValue("view", activity.getSearchControls());
    createAction(R.id.actions_toggleTouchManagerView).putValue("view", activity.getTouchView());
    createAction(R.id.mainmenu_force_portrait).putValue("mode", BookRotationType.PORTRAIT);
    createAction(R.id.mainmenu_force_landscape).putValue("mode", BookRotationType.LANDSCAPE);

    if (recreated) {
      return;
    }

    documentModel = ActivityControllerStub.DM_STUB;
    searchModel = new SearchModel(this);

    if (intent == null) {
      showErrorDlg(R.string.msg_bad_intent, intent);
      return;
    }

    final Uri data = intent.getData();
    if (data == null) {
      showErrorDlg(R.string.msg_no_intent_data, intent);
      return;
    }

    scheme = ContentScheme.getScheme(intent);
    if (scheme == ContentScheme.UNKNOWN) {
      showErrorDlg(R.string.msg_bad_intent, intent);
      return;
    }

    bookTitle = scheme.getResourceName(activity.getContentResolver(), data);
    codecType = CodecType.getByUri(bookTitle);

    if (codecType == null) {
      bookTitle = ContentScheme.getDefaultResourceName(data, "");
      codecType = CodecType.getByUri(bookTitle);
    }

    if (codecType == null) {
      final String type = intent.getType();
      LCTX.i("Book mime type: " + type);
      if (LengthUtils.isNotEmpty(type)) {
        codecType = CodecType.getByMimeType(type);
      }
    }

    LCTX.i("Book codec type: " + codecType);
    LCTX.i("Book title: " + bookTitle);
    if (codecType == null) {
      showErrorDlg(R.string.msg_unknown_intent_data_type, data);
      return;
    }

    documentModel = new DocumentModel(codecType);
    documentModel.addListener(ViewerActivityController.this);
    progressModel = new DecodingProgressModel();
    progressModel.addListener(ViewerActivityController.this);

    final Uri uri = data;
    if (scheme.temporary) {
      m_fileName = scheme.key;
      CacheManager.clear(scheme.key);
    } else {
      m_fileName = PathFromUri.retrieve(activity.getContentResolver(), uri);
    }

    bookSettings = SettingsManager.create(id, m_fileName, scheme.temporary, intent);
    SettingsManager.applyBookSettingsChanges(null, bookSettings);
  }