示例#1
0
 public ViewState takeTask(final long timeout, final TimeUnit unit, final boolean useLastState) {
   ViewState task = null;
   try {
     task = queue.poll(timeout, unit);
     if (task != null && useLastState) {
       final ArrayList<ViewState> list = new ArrayList<ViewState>();
       // Workaround for possible ConcurrentModificationException
       while (true) {
         list.clear();
         try {
           if (queue.drainTo(list) > 0) {
             task = list.get(list.size() - 1);
           }
           break;
         } catch (Throwable ex) {
           // Go to next attempt
           LCTX.e(
               "Unexpected error on retrieving last view state from draw queue: "
                   + ex.getMessage());
         }
       }
     }
   } catch (final InterruptedException e) {
     Thread.interrupted();
   } catch (Throwable ex) {
     // Go to next attempt
     LCTX.e("Unexpected error on retrieving view state from draw queue: " + ex.getMessage());
   }
   return task;
 }
示例#2
0
 public Region getRegion(final float x, final float y, final float width, final float height) {
   LCTX.d("getRegion(" + x + ", " + y + ", " + width + ", " + height + ")");
   for (final Region r : regions) {
     final RectF rect = r.getActualRect(width, height);
     LCTX.d("Region: " + rect);
     if (rect.left <= x && x < rect.right && rect.top <= y && y < rect.bottom) {
       return r;
     }
   }
   return null;
 }
示例#3
0
  public void setCurrentPageIndex(final PageIndex newIndex) {
    if (!CompareUtils.equals(currentIndex, newIndex)) {
      if (LCTX.isDebugEnabled()) {
        LCTX.d("Current page changed: " + "currentIndex" + " -> " + newIndex);
      }

      final PageIndex oldIndex = this.currentIndex;
      this.currentIndex = newIndex;

      this.<CurrentPageListener>getListener().currentPageChanged(oldIndex, newIndex);
    }
  }
示例#4
0
    public static Region fromJSON(final JSONObject json) throws JSONException {
      final JSONObject r = json.getJSONObject("rect");
      final Rect rect =
          new Rect(r.getInt("left"), r.getInt("top"), r.getInt("right"), r.getInt("bottom"));

      final Region region = new Region(rect);
      final JSONArray actions = json.getJSONArray("actions");
      for (int aIndex = 0; aIndex < actions.length(); aIndex++) {
        try {
          final JSONObject a = actions.getJSONObject(aIndex);
          final Touch type = Touch.valueOf(a.getString("type"));
          final String name = a.getString("name");
          final Integer id = ActionEx.getActionId(name);
          if (id != null) {
            region.setAction(type, id, a.getBoolean("enabled"));
          } else {
            LCTX.e("Unknown action name: " + name);
          }
        } catch (final JSONException ex) {
          throw new JSONException(
              "Old perssitent format found. Touch action are returned to default ones: "
                  + ex.getMessage());
        }
      }
      return region;
    }
示例#5
0
 public Integer getAction(
     final Touch type, final float x, final float y, final float width, final float height) {
   LCTX.d("getAction(" + type + ", " + x + ", " + y + ", " + width + ", " + height + ")");
   for (final Region r : regions) {
     final RectF rect = r.getActualRect(width, height);
     LCTX.d("Region: " + rect);
     if (rect.left <= x && x < rect.right && rect.top <= y && y < rect.bottom) {
       final ActionRef action = r.getAction(type);
       LCTX.d("Action: " + action);
       if (action != null && action.enabled) {
         return action.id;
       }
     }
   }
   return null;
 }
示例#6
0
  public static void loadFromSettings(final AppSettings newSettings) {
    profiles.clear();
    stack.clear();

    boolean fromJSON = false;
    final String str = newSettings.tapProfiles;
    if (LengthUtils.isNotEmpty(str)) {
      try {
        final List<TouchProfile> list = fromJSON(str);
        for (final TouchProfile p : list) {
          profiles.put(p.name, p);
        }
      } catch (final Throwable ex) {
        LCTX.e("Error on tap configuration load: ", ex);
      }
      fromJSON = profiles.containsKey(DEFAULT_PROFILE);
    }

    if (!fromJSON) {
      if (LCTX.isDebugEnabled()) {
        LCTX.d("Creating default tap configuration...");
      }
      final TouchProfile def = addProfile(DEFAULT_PROFILE);
      {
        final Region r = def.addRegion(0, 0, 100, 100);
        r.setAction(Touch.DoubleTap, R.id.actions_openOptionsMenu, true);
      }
      {
        final Region r = def.addRegion(0, 0, 100, 10);
        r.setAction(Touch.SingleTap, R.id.actions_verticalConfigScrollUp, true);
      }
      {
        final Region r = def.addRegion(0, 90, 100, 100);
        r.setAction(Touch.SingleTap, R.id.actions_verticalConfigScrollDown, true);
      }

      persist();
    }

    stack.addFirst(profiles.get(DEFAULT_PROFILE));
  }
示例#7
0
  public void initPages(
      final IActivityController base, final IActivityController.IBookLoadTask task) {
    recyclePages();

    final BookSettings bs = SettingsManager.getBookSettings();

    if (base == null || bs == null || context == null || decodeService == null) {
      return;
    }

    final IView view = base.getView();

    final CodecPageInfo defCpi = new CodecPageInfo();
    defCpi.width = (view.getWidth());
    defCpi.height = (view.getHeight());

    int viewIndex = 0;

    final long start = System.currentTimeMillis();
    try {
      final ArrayList<Page> list = new ArrayList<Page>();
      final CodecPageInfo[] infos = retrievePagesInfo(base, bs, task);

      for (int docIndex = 0; docIndex < infos.length; docIndex++) {
        if (!bs.splitPages
            || infos[docIndex] == null
            || (infos[docIndex].width < infos[docIndex].height)) {
          final Page page =
              new Page(
                  base,
                  new PageIndex(docIndex, viewIndex++),
                  PageType.FULL_PAGE,
                  infos[docIndex] != null ? infos[docIndex] : defCpi);
          list.add(page);
        } else {
          final Page page1 =
              new Page(
                  base, new PageIndex(docIndex, viewIndex++), PageType.LEFT_PAGE, infos[docIndex]);
          list.add(page1);
          final Page page2 =
              new Page(
                  base, new PageIndex(docIndex, viewIndex++), PageType.RIGHT_PAGE, infos[docIndex]);
          list.add(page2);
        }
      }
      pages = list.toArray(new Page[list.size()]);
      if (pages.length > 0) {
        createBookThumbnail(bs, pages[0], false);
      }
    } finally {
      LCTX.d("Loading page info: " + (System.currentTimeMillis() - start) + " ms");
    }
  }
示例#8
0
 public void draw(final ViewState viewState) {
   if (viewState != null) {
     // Workaround for possible ConcurrentModificationException
     while (true) {
       try {
         queue.offer(viewState);
         break;
       } catch (Throwable ex) {
         // Go to next attempt
         LCTX.e("Unexpected error on adding view state to draw queue: " + ex.getMessage());
       }
     }
   }
 }
示例#9
0
 protected void draw(final boolean useLastState) {
   final ViewState viewState = takeTask(1, TimeUnit.SECONDS, useLastState);
   if (viewState == null) {
     return;
   }
   Canvas canvas = null;
   try {
     canvas = surfaceHolder.lockCanvas(null);
     EventPool.newEventDraw(viewState, canvas).process();
   } catch (final Throwable th) {
     LCTX.e("Unexpected error on drawing: " + th.getMessage(), th);
   } finally {
     if (canvas != null) {
       surfaceHolder.unlockCanvasAndPost(canvas);
     }
   }
 }