示例#1
0
  /**
   * Parse XML Attributes. Should only be called once and at the end of the base class constructor.
   * The first-pass attempts to locate styleable attributes and apply those first. After that,
   * configurator-style attributes are applied, overriding any styleable attrs that may have been
   * previously applied.
   *
   * @param attrs
   */
  private void loadAttrs(AttributeSet attrs, int defStyle) {

    if (attrs != null) {

      Field styleableFieldInR = null;
      TypedArray typedAttrs = null;

      final String appPkg = getContext().getPackageName();
      Class styleableClass = null;
      try {
        /**
         * Need to retrieve R$styleable.class dynamically to avoid exceptions in environments where
         * this class does not exist, such as .jar users that have not merged the library's
         * attrs.xml with their own.
         */
        styleableClass = Class.forName(appPkg + ".R$styleable");

      } catch (ClassNotFoundException e) {
        // when running as a preview in IntelliJ or AndroidStudio it seems that the package of R is
        // something else; this fixes that issue:
        if (isInEditMode()) {
          styleableClass = R.styleable.class;
        }
      }

      if (styleableClass != null) {
        String styleableName = getClass().getName().substring(BASE_PACKAGE.length());
        styleableName = styleableName.replace('.', '_');
        try {
          /**
           * Use reflection to safely check for the existence of styleable defs for Plot and it's
           * derivatives. This safety check is necessary to avoid runtime exceptions in apps that
           * don't include Androidplot as a .aar and won't have access to the resources defined in
           * the core library.
           */
          styleableFieldInR = styleableClass.getField(styleableName);
        } catch (NoSuchFieldException e) {
          Log.d(TAG, "Styleable definition not found for: " + styleableName);
        }
        if (styleableFieldInR != null) {
          try {
            int[] resIds = (int[]) styleableFieldInR.get(null);
            typedAttrs = getContext().obtainStyledAttributes(attrs, resIds, defStyle, 0);
          } catch (IllegalAccessException e) {
            // nothing to do
          } finally {
            if (typedAttrs != null) {
              // apply derived class' attrs:
              processAttrs(typedAttrs);
              typedAttrs.recycle();
            }
          }
        }

        try {
          styleableFieldInR = styleableClass.getField(Plot.class.getSimpleName());
          if (styleableFieldInR != null) {
            int[] resIds = (int[]) styleableFieldInR.get(null);
            typedAttrs = getContext().obtainStyledAttributes(attrs, resIds, defStyle, 0);
          }
        } catch (IllegalAccessException e) {
          // nothing to do
        } catch (NoSuchFieldException e) {
          Log.d(TAG, "Styleable definition not found for: " + Plot.class.getSimpleName());
        } finally {
          if (typedAttrs != null) {
            // apply base attrs:
            processBaseAttrs(typedAttrs);
            typedAttrs.recycle();
          }
        }
      }

      // apply "configurator" attrs: (overrides any previously applied styleable attrs)
      // filter out androidplot prefixed attrs:
      HashMap<String, String> attrHash = new HashMap<String, String>();
      for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attrName = attrs.getAttributeName(i);

        // case insensitive check to see if this attr begins with our prefix:
        if (attrName != null && attrName.toUpperCase().startsWith(XML_ATTR_PREFIX.toUpperCase())) {
          attrHash.put(
              attrName.substring(XML_ATTR_PREFIX.length() + 1), attrs.getAttributeValue(i));
        }
      }
      Configurator.configure(getContext(), this, attrHash);
    }
  }
示例#2
0
  @Override
  public void run() {
    // TODO: Implement this method
    super.run();
    start = 0;
    end = 0;

    LoadPageImage imp;
    HashMap<String, Object> map = new HashMap<String, Object>();
    try {

      start = html.indexOf("page-submission", 0);
      start = html.indexOf("small_url =", start);
      end = html.indexOf("var full_url", start);
      s = "http:" + html.substring(start + 13, end - 3);
      final String img = s;
      map.put("img", s);
      end = html.indexOf(">Download<", end);
      start = html.lastIndexOf("href=", end);
      s = "http:" + html.substring(start + 6, end - 1);
      map.put("download", s);
      int std = s.lastIndexOf("/");
      String name = PageActivity.HOME_PATH + s.substring(std + 1, s.length());
      File f = new File(name);
      if (f.exists()) {
        Bitmap b;
        b = BitmapFactory.decodeFile(f.getPath());
        map.put("bitmap", b);
      } else {
        name = PageActivity.HOME_PATH + "s-" + s.substring(std + 1, s.length());
        f = new File(name);
        if (f.exists()) {
          Bitmap b;
          b = BitmapFactory.decodeFile(f.getPath());
          map.put("bitmap", b);
        } else {
          imp = new LoadPageImage();
          imp.start(img, -1, now);
        }
      }
      end = html.indexOf("Main Gallery", end);
      start = html.lastIndexOf("href=", end);
      end = html.indexOf("class=", start);
      s = html.substring(start + 6, end - 2);
      map.put("gallery", s);
      start = html.indexOf("<tr>\n<td", end);
      start = html.indexOf("<b>", start);
      end = html.indexOf("</b>", start);
      s = html.substring(start + 3, end);
      map.put("title", s);
      start = html.indexOf("href=", start);
      end = html.indexOf("><img", start);
      s = "http://www.furaffinity.net" + html.substring(start + 6, end - 1);
      map.put("userlink", s);
      start = html.indexOf("alt=", end);
      end = html.indexOf("\" src", start);
      s = html.substring(start + 5, end);
      map.put("username", s);
      start = html.indexOf("src=", end);
      end = html.indexOf("></a>", start);
      s = "http:" + html.substring(start + 5, end - 1);
      imp = new LoadPageImage();
      imp.start(s, -2, now);
      map.put("usericon", s);
      start = html.indexOf("<br/><br/>", end);
      end = html.indexOf("</td>\n</tr>", start);
      int st = start;
      int ed = start - 2;
      String t = "";
      s = "";
      while (html.indexOf("<br/>", st + 1) < end - 6) {
        st = html.indexOf("<br/>", ed);
        ed = html.indexOf("<br/>", st + 1);
        t = html.substring(st + 5, ed);
        if (t.indexOf("href=") != -1) {
          int i1;
          int i2;
          i1 = t.indexOf("alt=\"", 0);
          i2 = t.indexOf("\"/>", i1);
          try {
            t = " @ " + t.substring(i1 + 5, i2) + " ";
          } catch (Exception e) {
            t = "";
          }
        }
        t = t.replace("</td>", "");
        t = t.replace("<td>", "");
        t = t.replace("</tr>", "");
        t = t.replace("<tr>", "");
        t = t.replace("</table>", "");
        t = t.replace("<table>", "");
        t = t.replace("<br>", "");
        t = t.replace("</br>", "");
        if (t.indexOf("bbcode") != -1) {
          t = "";
        }
        s += t;
      }

      map.put("info", s);
      if (now == PageActivity.now) {
        Message msg = Message.obtain();
        msg.arg2 = now;
        msg.obj = map;
        msg.what = 5;
        PageActivity.hander.sendMessage(msg);
      }
    } catch (Exception e) {
      File f = new File(PageActivity.HOME_PATH + "LOG/lastPage.html");
      if (f.exists()) {
        f.renameTo(new File(PageActivity.HOME_PATH + "LOG/lastErrorPage.html"));
      }
      Message msg = Message.obtain();
      msg.arg2 = now;
      msg.obj = map;
      msg.what = 998;
      PageActivity.hander.sendMessage(msg);
    }
  }