Ejemplo n.º 1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
      LayoutInflater inflater =
          (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      view = inflater.inflate(R.layout.fb_listitem, null);
    }

    DashboardBaseListElement listElement = _listElements.get(position);
    if (listElement != null) {
      view.setOnClickListener(listElement.getOnClickListener());
      ImageView icon = (ImageView) view.findViewById(R.id.icon);
      TextView text1 = (TextView) view.findViewById(R.id.text1);
      TextView text2 = (TextView) view.findViewById(R.id.text2);
      if (icon != null) {
        UrlImageViewHelper.setUrlDrawable(icon, listElement.getIcon());
      }
      if (text1 != null) {
        text1.setText(listElement.getText1());
      }
      if (text2 != null) {
        if (listElement.getText2() != null) {
          text2.setVisibility(View.VISIBLE);
          text2.setText(listElement.getText2());
        } else {
          text2.setVisibility(View.GONE);
        }
      }
    }
    return view;
  }
  @Override
  public void download(
      final Context context,
      final String url,
      final String filename,
      final UrlDownloaderCallback callback,
      final Runnable completion) {
    final AsyncTask<Void, Void, Void> downloader =
        new AsyncTask<Void, Void, Void>() {
          @Override
          protected Void doInBackground(final Void... params) {
            try {
              final ContentResolver cr = context.getContentResolver();
              InputStream is = cr.openInputStream(Uri.parse(url));
              callback.onDownloadComplete(ContentUrlDownloader.this, is, null);
              return null;
            } catch (final Throwable e) {
              e.printStackTrace();
              return null;
            }
          }

          @Override
          protected void onPostExecute(final Void result) {
            completion.run();
          }
        };

    UrlImageViewHelper.executeTask(downloader);
  }
Ejemplo n.º 3
0
 @Override
 protected void onDialogClosed(boolean positiveResult) {
   if (positiveResult) {
     CPDecksDBHelper.clearCachedApiData();
     UrlImageViewHelper.cleanup(mContext, 1);
   }
   super.onDialogClosed(positiveResult);
 }
Ejemplo n.º 4
0
  public void addImageViewUrl(String src) {

    ImageView imgView = new ImageView(this);
    if (position_status == FRONT) ViewList.add(imgView);
    else ViewListBack.add(imgView);
    RelativeLayout.LayoutParams layoutParams =
        new RelativeLayout.LayoutParams(OriImgSize, OriImgSize);
    layoutParamsList.add(layoutParams);
    mRrootLayout.addView(imgView);
    imgView.setLayoutParams(layoutParams);
    imgView.setOnTouchListener(this);
    UrlImageViewHelper.setUrlDrawable(imgView, src);
    imgView.setVisibility(View.VISIBLE);
  }
 @Override
 public void onBindViewHolder(MainViewHolder holder, final int position) {
   GroverDriver grove = groves.get(position);
   ImageView grove_image = holder.grove_image;
   UrlImageViewHelper.setUrlDrawable(
       grove_image,
       grove.ImageURL,
       R.drawable.grove_no,
       UrlImageViewHelper.CACHE_DURATION_INFINITE);
   //            String name = grove.GroveName.replaceFirst("Grove[\\s_-]+", "");
   holder.mGroveNameView.setText(grove.GroveName);
   String interfaceType = grove.InterfaceType;
   if (interfaceType.equals("GPIO")) interfaceType = "Digital";
   holder.mGroveInterfaceView.setText(interfaceType);
 }
  // Replaces the contents of a view at each position
  public void onBindViewHolder(final MessageRow messageRow, int position) {
    final NBMessageItem tMessage = mDataset.get(position);

    messageRow.itemName.setText(tMessage.subject);
    messageRow.itemSubject.setText(tMessage.body);
    messageRow.itemDate.setText(tMessage.createdDate);

    UrlImageViewHelper.setUrlDrawable(
        messageRow.itemImage, tMessage.senderThumbnail, R.drawable.default_profile_image);

    if (tMessage.status.equals("read") && tMessage.type.equals("inbox"))
      messageRow.singleMessageLayout.setBackgroundColor(Color.LTGRAY);

    messageRow.singleMessageLayout.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ColorDrawable bg = (ColorDrawable) messageRow.singleMessageLayout.getBackground();
            int colorFrom = bg.getColor();
            int colorTo = Color.rgb(230, 230, 230);
            ValueAnimator colorAnimation =
                ValueAnimator.ofObject(new ArgbEvaluator(), colorTo, colorFrom);
            colorAnimation.setDuration(800);
            colorAnimation.addUpdateListener(
                new ValueAnimator.AnimatorUpdateListener() {
                  @Override
                  public void onAnimationUpdate(ValueAnimator animator) {
                    messageRow.singleMessageLayout.setBackgroundColor(
                        (Integer) animator.getAnimatedValue());
                  }
                });
            colorAnimation.start();

            Intent i = new Intent(mContext, MessagesReadActivity.class);

            i.putExtra("messageId", tMessage.messageId);
            i.putExtra("messageType", tMessage.type);

            mContext.startActivity(i);
          }
        });
  }
    @Override
    public View instantiateItem(ViewGroup container, int position) {

      String imageUrl = mImages.get(position);
      View layout = (View) getLayoutInflater().inflate(R.layout.observation_photo, null, false);
      container.addView(layout, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      ImageView imageView = (ImageView) layout.findViewById(R.id.id_pic);
      final ProgressBar loading = (ProgressBar) layout.findViewById(R.id.id_pic_loading);

      if (imageUrl == null) {
        // Show a default taxon image
        imageView.setImageResource(mDefaultTaxonIcon);
      } else {
        loading.setVisibility(View.VISIBLE);
        imageView.setVisibility(View.INVISIBLE);
        final PhotoViewAttacher attacher = new PhotoViewAttacher(imageView);
        // Show a photo
        UrlImageViewHelper.setUrlDrawable(
            imageView,
            imageUrl,
            mDefaultTaxonIcon,
            new UrlImageViewCallback() {
              @Override
              public void onLoaded(
                  ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                loading.setVisibility(View.GONE);
                imageView.setVisibility(View.VISIBLE);
                attacher.update();
              }

              @Override
              public Bitmap onPreSetBitmap(
                  ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                // No post-processing of bitmap
                return loadedBitmap;
              }
            });
      }

      return layout;
    }
Ejemplo n.º 8
0
  /** Change the current image in image set */
  private void changeImage(
      Button previousButton,
      Button forwardButton,
      final int index,
      SourceContent sourceContent,
      TextView countTextView,
      ImageView imageSet,
      String url,
      final int current) {

    if (currentImageSet[index] != null) {
      currentImage = currentImageSet[index];
      imageSet.setImageBitmap(currentImage);
    } else {
      UrlImageViewHelper.setUrlDrawable(
          imageSet,
          url,
          new UrlImageViewCallback() {

            @Override
            public void onLoaded(
                ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
              if (loadedBitmap != null) {
                currentImage = loadedBitmap;
                currentImageSet[index] = loadedBitmap;
              }
            }
          });
    }

    currentItem = index;

    if (index == 0) previousButton.setEnabled(false);
    else previousButton.setEnabled(true);

    if (index == 0) forwardButton.setEnabled(false);
    else forwardButton.setEnabled(true);

    countTextView.setText((index + 1) + " " + getString(R.string.of) + " " + 0);
  }
Ejemplo n.º 9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_topic);

    Intent intent = getIntent();
    topicId = intent.getStringExtra(TOPIC_ID);
    topicDesc = intent.getStringExtra(TOPIC_DESC);
    topicPoints = intent.getStringExtra(TOPIC_POINTS);
    topicComments = intent.getStringExtra(TOPIC_COMMENTS);
    topicImg = intent.getStringExtra(TOPIC_IMG);

    ivTopicImg = (ImageView) findViewById(R.id.ivImageTPC);
    tvTopicDesc = (TextView) findViewById(R.id.tvCaptionTPC);
    tvTopicPoints = (TextView) findViewById(R.id.tvThumbsUpTPC);
    tvTopicComments = (TextView) findViewById(R.id.tvCommentsTPC);

    UrlImageViewHelper.setUrlDrawable(ivTopicImg, AppConstants.WS_BASE_URL + topicImg);

    tvTopicDesc.setText(topicDesc);
    tvTopicPoints.setText(topicPoints + " Points");
    tvTopicComments.setText(topicComments + " Comments");

    // ListView

    // Get ListView object from xml
    listView = (ListView) findViewById(R.id.commentList);

    adapter = new CommentsListAdapter(ViewTopicActivity.this, list);
    // Assign adapter to ListView
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(ViewTopicActivity.this, ViewTopicActivity.class);
            i.putExtra(ViewTopicActivity.TOPIC_ID, list.get(position).get("id"));
            i.putExtra(ViewTopicActivity.TOPIC_DESC, list.get(position).get("caption"));
            i.putExtra(ViewTopicActivity.TOPIC_COMMENTS, list.get(position).get("totalcomments"));
            i.putExtra(ViewTopicActivity.TOPIC_POINTS, list.get(position).get("thumpsup"));
            i.putExtra(ViewTopicActivity.TOPIC_IMG, list.get(position).get("image"));
            startActivity(i);
          }
        });

    TelephonyManager telephonyManager =
        (TelephonyManager) ViewTopicActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
    String device_id = telephonyManager.getSimSerialNumber();
    String cmd = "getComments";

    JSONObject request = new JSONObject();
    try {
      request.put("deviceid", device_id);
      request.put("cmd", cmd);
      request.put("topicid", topicId);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    GetCommentsAsync task = new GetCommentsAsync();
    task.execute(request);
  }
Ejemplo n.º 10
0
  public void updateFragment() {
    String source = mWord.getSource();
    String target = mWord.getTarget();
    String targetPhonetics = mWord.getTargetPhonetics();

    CPDecksAccount account = CPDecksAccount.getInstance();

    int currentFrontRow = 0;
    if (account.getFlashCardsShowTarget()) {
      mRowsFront[currentFrontRow].setVisibility(View.VISIBLE);
      mRowsFront[currentFrontRow].setText(target);
      ++currentFrontRow;
    }
    if (account.getFlashCardsShowTargetPhonetics()) {
      mRowsFront[currentFrontRow].setVisibility(View.VISIBLE);
      mRowsFront[currentFrontRow].setText(targetPhonetics);
      ++currentFrontRow;
    }
    if (account.getFlashCardsShowSource()) {
      mRowsFront[currentFrontRow].setVisibility(View.VISIBLE);
      mRowsFront[currentFrontRow].setText(source);
      ++currentFrontRow;
    }

    mImageFront.setImageDrawable(null);
    if (account.getFlashCardsShowImage()) {
      File imgFile = new File(mWord.getImageFile());
      if (imgFile.exists()) {
        Bitmap imageBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        mImageFront.setImageBitmap(imageBitmap);
      } else if (HttpConnectionHelper.isProperUrl(mWord.getImageUrl())) {
        UrlImageViewHelper.setUrlDrawable(
            mImageFront, mWord.getImageUrl(), R.drawable.default_image);
      } else if (currentFrontRow == 0) {
        mRowsFront[currentFrontRow].setVisibility(View.VISIBLE);
        mRowsFront[currentFrontRow].setText(target);
        ++currentFrontRow;
        mRowsFront[currentFrontRow].setVisibility(View.VISIBLE);
        mRowsFront[currentFrontRow].setText(targetPhonetics);
        ++currentFrontRow;
      }
    }

    if (HttpConnectionHelper.isProperUrl(mWord.getTargetAudio().getAudioUrl())) {
      if (account.getFlashCardsShowAudio()) {
        mPlayButtonFront.setVisibility(View.VISIBLE);
      }
      mPlayButtonBack.setVisibility(View.VISIBLE);

      if (new File(mWord.getTargetAudio().getAudioFile()).exists()) {
        mPlayButtonFront.setBackgroundResource(R.drawable.sound_downloaded);
        mPlayButtonBack.setBackgroundResource(R.drawable.sound_downloaded);
      }

      mPlayButtonFront.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              ((CPDecksCanPlaySound) getActivity())
                  .playSound(
                      mWord.getTargetAudio(), v, R.drawable.sound_red, R.drawable.sound_downloaded);
              mPlayButtonBack.setBackgroundResource(R.drawable.sound_downloaded);
            }
          });

      mPlayButtonBack.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              ((CPDecksCanPlaySound) getActivity())
                  .playSound(
                      mWord.getTargetAudio(), v, R.drawable.sound_red, R.drawable.sound_downloaded);
            }
          });
    } else {
      mPlayButtonFront.setVisibility(View.INVISIBLE);
      mPlayButtonBack.setVisibility(View.INVISIBLE);
    }

    mRowsBack[0].setText(target);
    mRowsBack[1].setText(targetPhonetics);
    mRowsBack[2].setText(source);
  }