Esempio n. 1
0
  /**
   * Download resources if needed and save item/category info in the database.
   *
   * @param params
   * @return
   */
  @Override
  protected List<Item> doInBackground(String... params) {
    String content = HttpManager.getDate(params[0]);
    // Get all parsed items
    List<Item> items = ItemJSONParser.parseFeed(content);

    if (items.size() == 0) {
      Log.i(TAG, "No update needed");
    } else {

      // Get image for each item
      for (Item item : items) {
        // Download item image and set
        Bitmap bitmap = ImageDownloader.download(this.SITE_URL + item.getImgLink());
        item.setBitmap(bitmap);

        // Save file to internal storage
        ImageDownloader.saveToInternalStorage(this.mainActivity, item);
        // Save items info in database
        this.db.addItem(item);
        // Save category if new
        if (!this.db.categoryExists(item.getCategoryId())) {
          this.db.addCategory(item);
        }
      }
    }
    return null;
  }
  private void sendImageRequest(boolean allowCachedResponse) {
    try {
      ImageRequest.Builder requestBuilder =
          new ImageRequest.Builder(
              getContext(), ImageRequest.getProfilePictureUrl(profileId, queryWidth, queryHeight));

      ImageRequest request =
          requestBuilder
              .setAllowCachedRedirects(allowCachedResponse)
              .setCallerTag(this)
              .setCallback(
                  new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                      processResponse(response);
                    }
                  })
              .build();

      // Make sure to cancel the old request before sending the new one to prevent
      // accidental cancellation of the new request. This could happen if the URL and
      // caller tag stayed the same.
      if (lastRequest != null) {
        ImageDownloader.cancelRequest(lastRequest);
      }
      lastRequest = request;

      ImageDownloader.downloadAsync(request);
    } catch (MalformedURLException e) {
      Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, e.toString());
    }
  }
Esempio n. 3
0
  public Story loadedStoryAtIndex(int i) {
    Story s = stories.get(i);
    StoryParser.fillData(s);
    ImageDownloader downloader = new ImageDownloader(s.imgUrl);
    s.image = downloader.go();

    return stories.get(i);
  }
Esempio n. 4
0
    @Override
    protected void onPostExecute(String result) {
      super.onPostExecute(result);

      progressDialog.dismiss();

      // download images
      ImageDownloader getImages = new ImageDownloader(activity);
      getImages.execute();
    }
  public void downloadImage(View view) {
    // http://www.howbigismypotato.com/images/potato.jpg

    ImageDownloader task = new ImageDownloader();
    Bitmap myImage;

    try {
      myImage = task.execute("http://www.howbigismypotato.com/images/potato.jpg").get();

      downloadedImage.setImageBitmap(myImage);

    } catch (Exception e) {
      e.printStackTrace();
    }
    Log.i("interact", "button tapped");
  }
    public InputStream getStream(String s, Object obj)
        throws IOException
    {
        static class _cls1
        {

            static final int $SwitchMap$com$nostra13$universalimageloader$core$download$ImageDownloader$Scheme[];

            static 
            {
                $SwitchMap$com$nostra13$universalimageloader$core$download$ImageDownloader$Scheme = new int[ImageDownloader.Scheme.values().length];
                try
                {
                    $SwitchMap$com$nostra13$universalimageloader$core$download$ImageDownloader$Scheme[ImageDownloader.Scheme.HTTP.ordinal()] = 1;
                }
                catch (NoSuchFieldError nosuchfielderror1) { }
                try
                {
                    $SwitchMap$com$nostra13$universalimageloader$core$download$ImageDownloader$Scheme[ImageDownloader.Scheme.HTTPS.ordinal()] = 2;
                }
                catch (NoSuchFieldError nosuchfielderror)
                {
                    return;
                }
            }
        }

        switch (_cls1..SwitchMap.com.nostra13.universalimageloader.core.download.ImageDownloader.Scheme[ImageDownloader.Scheme.ofUri(s).ordinal()])
        {
        default:
            return wrappedDownloader.getStream(s, obj);

        case 1: // '\001'
        case 2: // '\002'
            throw new IllegalStateException();
Esempio n. 7
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebook);

    //	필요한 위젯들 전부 로딩
    faceBook_myTitleTxtVw = (TextView) findViewById(R.id.faceBook_movieTitle);
    faceBook_myWhenTxtVw = (TextView) findViewById(R.id.faceBook_myWhenTxtVw);
    faceBook_myWhereTxtVw = (TextView) findViewById(R.id.faceBook_myWhereTxtVw);
    faceBook_myWithTxtVw = (TextView) findViewById(R.id.faceBook_myWhoTxtVw);
    faceBook_myGenreTxtVw = (TextView) findViewById(R.id.faceBook_myGenreTxtVw);
    faceBook_myOpenInfoTxtVw = (TextView) findViewById(R.id.faceBook_myOpenInfoTxtVw);
    faceBook_myActorTxtVw = (TextView) findViewById(R.id.faceBook_myActorTxtVw);
    faceBook_myDirectorTxtVw = (TextView) findViewById(R.id.faceBook_myDirectorTxtVw);

    faceBook_myThumbnail = (ImageView) findViewById(R.id.faceBook_myThumbnail);
    faceBook_myRatingBar = (RatingBar) findViewById(R.id.faceBook_myRatingBar);

    //	전달받은 인텐트를 가져온다.
    Intent intent = getIntent();
    //	인텐트가 존재하면
    if (intent != null) {
      //	movie객체를 가져와서 데이터를 뿌려준다.
      Movie movie = (Movie) intent.getSerializableExtra("movie");
      this.movie = movie;

      faceBook_myTitleTxtVw.setText(movie.getTitle());
      String getWhen = movie.getWhen();
      String year = getWhen.substring(0, 4);
      String month = getWhen.substring(4, 5);
      String day = getWhen.substring(5, 7);
      faceBook_myWhenTxtVw.setText(year + "년 " + month + "월 " + day + "일");
      faceBook_myWithTxtVw.setText(movie.getWith());
      faceBook_myWhereTxtVw.setText(movie.getWhere());
      rating =
          (float) ((movie.getGrade().equals("")) ? 0.0 : Float.parseFloat(movie.getGrade()))
              / (float) 2.0;
      faceBook_myRatingBar.setRating(rating);
      faceBook_myGenreTxtVw.setText("		● 장르 : " + movie.getGenre());
      faceBook_myActorTxtVw.setText("		● 감독 : " + movie.getDirector());
      faceBook_myActorTxtVw.setText("		● 배우 : " + Arrays.toString(movie.getActor()));
      faceBook_myOpenInfoTxtVw.setText("		● 개봉일 : " + movie.getOpenInfo());

      imageDownloader.download(movie.getThumbnail(), faceBook_myThumbnail);
    }

    mEtContent = (EditText) findViewById(R.id.faceBook_etContent);
    mBtnFeed = (Button) findViewById(R.id.faceBook_btnFeed);
    mBtnFeed.setOnClickListener(this);
    faceBook_btnLogout = (Button) findViewById(R.id.faceBook_btnLogout);
    faceBook_btnLogout.setOnClickListener(this);

    mFacebookAccessToken = getAppPreferences(this, "ACCESS_TOKEN");
    if (!mFacebookAccessToken.equals("")) {
      mFacebook.setAccessToken(mFacebookAccessToken);
    }
  }
 @Override
 public InputStream getStream(String imageUri, Object extra) throws IOException {
   InputStream imageStream = wrappedDownloader.getStream(imageUri, extra);
   switch (Scheme.ofUri(imageUri)) {
     case HTTP:
     case HTTPS:
       return new FlushedInputStream(imageStream);
     default:
       return imageStream;
   }
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   ViewHolder holder;
   if (convertView == null) {
     convertView = li.inflate(R.layout.galleryitem, null);
     holder = new ViewHolder();
     holder.iv = (ImageView) convertView.findViewById(R.id.galleryitem_iv);
     convertView.setTag(holder);
   } else {
     holder = (ViewHolder) convertView.getTag();
   }
   imageDownloader.download(ConstantBean.ROOT + urls[position], holder.iv);
   return convertView;
 }
 @Override
 protected Bitmap doInBackground(Void... params) {
   logger.debug("DownloadTask: Start downloading from {}", src);
   return imageDownloader.downloadBitmap(src, reqWidth, reqHeight);
 }
Esempio n. 11
0
  @Override
  public void run() {
    String after = "";
    int j = 1;
    while (j < n + 1) {
      if (Main.proceed) {
        String afterString = "";
        if (j != 1) {
          afterString = "&after=" + after;
        }
        // can ignore trying to find a "after" value
        try {
          String subfull =
              "http://www.reddit.com/r/"
                  + sub
                  + "/"
                  + s.toString().toLowerCase()
                  + ".json?t="
                  + t.toString().toLowerCase()
                  + "&limit=1"
                  + afterString;
          System.out.println(subfull);
          JSONObject json =
              JSONReader.readJsonFromUrl(
                  "http://www.reddit.com/r/"
                      + sub
                      + "/"
                      + s.toString().toLowerCase()
                      + ".json?t="
                      + t.toString().toLowerCase()
                      + "&limit=1"
                      + afterString);

          JSONObject data = json.getJSONObject("data");

          after = data.getString("after");
          System.out.println(after);
          JSONArray children = data.getJSONArray("children");
          if (!children.isNull(0)) {
            JSONObject value = children.getJSONObject(0).getJSONObject("data");
            // after = (String)
            // children.getJSONObject(0).getString("kind")+"_"+value.getString("id");
            System.out.println(
                "domain: " + value.getString("domain") + " url: " + value.getString("url"));
            if ((value.getString("domain").equals("imgur.com")
                    && !value.getString("url").contains("/a/"))
                || value.getString("url").contains(".jpg")
                || value.getString("url").contains(".jpeg")
                || value.getString("url").contains(".png")) {
              String image = value.getString("url");
              if (value.getString("domain").equals("imgur.com") && !image.contains(".jpg")) {
                if (image.contains(",")) {
                  String[] parts = image.split(",");
                  image = parts[0];
                }
                if (image.contains("/a/")) {
                  image = image + "#0";
                }
                image = image + ".jpg";
              }
              ImageDownloader.getImage(image, folder, j);
              String path = folder + "\\" + j + ".jpg";
              File theDir = new File(folder);
              if (!theDir.exists()) {
                boolean result = theDir.mkdir();
              }
              System.out.println(path);

              SPI.INSTANCE.SystemParametersInfo(
                  new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),
                  new UINT_PTR(0),
                  path,
                  new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));
              waiting(interval);

            } else {
              System.out.println("Skipping not a jpg");
            }
            if (j == n || after.equals("null")) {
              j = 1;
            } else {
              j++;
            }
          } else {
            j = 1;
          }
          // System.out.println(after);
        } catch (Exception e) {
          e.printStackTrace();
        }

      } else {
        j = n + 1;
      }
    }
  }
  private void updateUI() {
    if (!isAdded()) {
      return;
    }
    if (isSessionOpen()) {
      connectedStateLabel.setTextColor(
          getResources()
              .getColor(
                  AirFacebookExtension.context.getResourceId(
                      "color.com_facebook_usersettingsfragment_connected_text_color")));
      connectedStateLabel.setShadowLayer(
          1f,
          0f,
          -1f,
          getResources()
              .getColor(
                  AirFacebookExtension.context.getResourceId(
                      "color.com_facebook_usersettingsfragment_connected_shadow_color")));

      if (user != null) {
        ImageRequest request = getImageRequest();
        if (request != null) {
          URL requestUrl = request.getImageUrl();
          // Do we already have the right picture? If so, leave it alone.
          if (!requestUrl.equals(connectedStateLabel.getTag())) {
            if (user.getId().equals(userProfilePicID)) {
              connectedStateLabel.setCompoundDrawables(null, userProfilePic, null, null);
              connectedStateLabel.setTag(requestUrl);
            } else {
              ImageDownloader.downloadAsync(request);
            }
          }
        }
        connectedStateLabel.setText(user.getName());
      } else {
        connectedStateLabel.setText(
            getResources()
                .getString(
                    AirFacebookExtension.context.getResourceId(
                        "string.com_facebook_usersettingsfragment_logged_in")));
        Drawable noProfilePic =
            getResources()
                .getDrawable(
                    AirFacebookExtension.context.getResourceId(
                        "drawable.com_facebook_profile_default_icon"));
        noProfilePic.setBounds(
            0,
            0,
            getResources()
                .getDimensionPixelSize(
                    AirFacebookExtension.context.getResourceId(
                        "dimen.com_facebook_usersettingsfragment_profile_picture_width")),
            getResources()
                .getDimensionPixelSize(
                    AirFacebookExtension.context.getResourceId(
                        "dimen.com_facebook_usersettingsfragment_profile_picture_height")));
        connectedStateLabel.setCompoundDrawables(null, noProfilePic, null, null);
      }
    } else {
      int textColor =
          getResources()
              .getColor(
                  AirFacebookExtension.context.getResourceId(
                      "color.com_facebook_usersettingsfragment_not_connected_text_color"));
      connectedStateLabel.setTextColor(textColor);
      connectedStateLabel.setShadowLayer(0f, 0f, 0f, textColor);
      connectedStateLabel.setText(
          getResources()
              .getString(
                  AirFacebookExtension.context.getResourceId(
                      "string.com_facebook_usersettingsfragment_not_logged_in")));
      connectedStateLabel.setCompoundDrawables(null, null, null, null);
      connectedStateLabel.setTag(null);
    }
  }
 public static void clearCaches(Context context) {
   ImageDownloader.clearCache(context);
 }
 public void downloadImageFromUri(String uri) {
   if (!TextUtils.isEmpty(uri)) {
     ImageDownloader.loadImage(getContext(), "file:///" + uri, this);
   }
 }
 public void downloadImageFromURL(String url, int downloadIndicator) {
   ImageDownloader.loadImage(getContext(), url, this, downloadIndicator);
 }
  public void downloadImageFromURL(String url) {

    if (!TextUtils.isEmpty(url)) {
      ImageDownloader.loadImage(getContext(), url, this);
    }
  }