예제 #1
0
  public static Boolean updateArtists(StaticDataStore db) {

    ArrayList<ArrayList<String>> artists = new ArrayList<ArrayList<String>>();
    int numArtists;

    HtmlCleaner pageParser = new HtmlCleaner();
    CleanerProperties props = pageParser.getProperties();
    props.setAllowHtmlInsideAttributes(true);
    props.setAllowMultiWordAttributes(true);
    props.setRecognizeUnicodeChars(true);
    props.setOmitComments(true);

    try {
      String url =
          "http://www.archive.org/browse.php?field=/metadata/bandWithMP3s&collection=etree";

      HttpParams params = new BasicHttpParams();
      int timeout = (int) (15 * DateUtils.SECOND_IN_MILLIS);
      HttpConnectionParams.setConnectionTimeout(params, timeout);
      HttpConnectionParams.setSoTimeout(params, timeout);
      HttpClient client = new DefaultHttpClient(params);

      HttpGet request = new HttpGet(url);
      HttpResponse response = client.execute(request);
      StatusLine status = response.getStatusLine();
      if (status.getStatusCode() == HttpStatus.SC_OK) {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        TagNode node = pageParser.clean(responseHandler.handleResponse(response));
        client.getConnectionManager().shutdown();
        // XPATH to get the nodes that we Want.
        Object[] artistsNodes = node.evaluateXPath("//tr[@valign='top']//li");

        numArtists = artistsNodes.length;

        for (int i = 0; i < numArtists; i++) {

          // Cast the artistNode as a TagNode.
          TagNode artist = ((TagNode) artistsNodes[i]);
          // Grab the first child node, which is the link to the artist's page.
          // The inner HTML of this node will be the title.
          TagNode artistTitleSubNode = artist.getChildTags()[0];
          // Remove the child node, so that the inner HTML of the artistNode
          // only contains the number of shows that the artist has.
          artist.removeChild(artistTitleSubNode);
          String artistTitle = pageParser.getInnerHtml(artistTitleSubNode);

          if (artistTitle != null) {
            ArrayList<String> artistPair = new ArrayList<String>();
            artistPair.add(
                artistTitle
                    .replace("&apos;", "'")
                    .replace("&gt;", ">")
                    .replace("&lt;", "<")
                    .replace("&quot;", "\"")
                    .replace("&amp;", "&"));
            artistPair.add(pageParser.getInnerHtml(artist).trim());
            /*
             * VibeVault.db.addArtist(artistTitle, pageParser
             * .getInnerHtml(artist).trim());
             */
            artists.add(artistPair);
          }
        }
        if (artists.size() > 0) {
          db.insertArtistBulk(artists);
          String s = DateFormat.format("yyyy-MM-dd", new GregorianCalendar().getTime()).toString();
          db.updatePref("artistUpdate", s);

        } else {

        }
      } else {
        client.getConnectionManager().shutdown();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return true;
  }
예제 #2
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_screen);

    Object retained = getLastNonConfigurationInstance();

    if (retained instanceof UpgradeTask) {
      Logging.Log(LOG_TAG, "UpgradeTask retained");
      upgradeTask = (UpgradeTask) retained;
      upgradeTask.setActivity(this);
    } else {
      // upgradeTask = new UpgradeTask(this);
    }

    int[] gradientColors = {0, 0xFF127DD4, 0};
    int curOrientation = this.getResources().getConfiguration().orientation;
    // FIXME
    separator1 = (ImageView) findViewById(R.id.separator1);
    separator1.setBackgroundDrawable(
        new GradientDrawable(
            curOrientation == Configuration.ORIENTATION_PORTRAIT
                ? Orientation.RIGHT_LEFT
                : Orientation.RIGHT_LEFT,
            gradientColors));
    // separator1.setBackground(new GradientDrawable(Orientation.RIGHT_LEFT, gradientColors));
    separator2 = (ImageView) findViewById(R.id.separator2);
    separator2.setBackgroundDrawable(
        new GradientDrawable(
            curOrientation == Configuration.ORIENTATION_PORTRAIT
                ? Orientation.RIGHT_LEFT
                : Orientation.TOP_BOTTOM,
            gradientColors));
    // separator2.setBackground(new GradientDrawable(Orientation.RIGHT_LEFT, gradientColors));
    separator3 = (ImageView) findViewById(R.id.separator3);
    separator3.setBackgroundDrawable(
        new GradientDrawable(
            curOrientation == Configuration.ORIENTATION_PORTRAIT
                ? Orientation.TOP_BOTTOM
                : Orientation.TOP_BOTTOM,
            gradientColors));
    // separator3.setBackground(new GradientDrawable(Orientation.TOP_BOTTOM, gradientColors));

    searchButton = (ImageButton) findViewById(R.id.HomeSearch);
    recentButton = (ImageButton) findViewById(R.id.HomeRecent);
    downloadButton = (ImageButton) findViewById(R.id.HomeDownload);
    playingButton = (ImageButton) findViewById(R.id.HomePlaying);
    featuredShowsButton = (ImageButton) findViewById(R.id.HomeFeatured);
    browseArtistsButton = (ImageButton) findViewById(R.id.HomeBrowse);

    db = StaticDataStore.getInstance(this);
    //		setImageButtonToToast();
    //		upgradeTask = new UpgradeTask(this);
    //		upgradeTask.execute();
    if (db.needsUpgrade && upgradeTask == null) { // DB needs updating
      setImageButtonToToast();
      upgradeTask = new UpgradeTask(this);
      upgradeTask.execute();
    } else { // DB Up to date, check artist date
      setImageButtonToFragments();
      if (needsArtistFetching() && upgradeTask == null) {
        upgradeTask = new UpgradeTask(this);
        upgradeTask.execute();
      }
    }

    if (db.dbCopied && !Boolean.parseBoolean(db.getPref("splashShown"))) {
      this.showDialog(
          this.getResources().getString(R.string.splash_screen), "Welcome to Vibe Vault 4");
      db.updatePref("splashShown", "true");
    } else if (db.needsUpgrade) {
      this.showDialog(
          this.getResources().getString(R.string.splash_screen), "Welcome to Vibe Vault 4");
    }
  }