壁纸无限期地变化

时间:2018-03-01 06:40:50

标签: java android

下面是我的适配器类。壁纸代码用于将图库中的所有图片设置为壁纸。 我希望壁纸改变的东西能无限期地进行。而这里只发生一次迭代。

我的适配器类代码是:

public class PhotoListAdapter extends 
  ViewHolderAdapter<PhotoListAdapter.PhotoViewHolder, PhotoInfo> {

private List<PhotoInfo> mSelectList;
private int mScreenWidth;
private int mRowWidth;

private Activity mActivity;

public PhotoListAdapter(Activity activity, List<PhotoInfo> list, List<PhotoInfo> selectList, int screenWidth) {
    super(activity, list);
    this.mSelectList = selectList;
    this.mScreenWidth = screenWidth;
    this.mRowWidth = mScreenWidth/3;
    this.mActivity = activity;
}

@Override
public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int position) {
    View view = inflate(R.layout.gf_adapter_photo_list_item, parent);
    setHeight(view);
    return new PhotoViewHolder(view);
}

@Override
public void onBindViewHolder(PhotoViewHolder holder, int position) {

          PhotoInfo photoInfo = getDatas().get(position);
          String path = "";
          if (photoInfo != null) {
              path = photoInfo.getPhotoPath();
              Log.d("PHOTOPATH", "Photopath: " + path);
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              BitmapFactory.Options options = new BitmapFactory.Options();
              options.inPreferredConfig = Bitmap.Config.ARGB_8888;
              Bitmap bitmap = BitmapFactory.decodeFile(path, options);
              WallpaperManager myWallpaperManager
                      = WallpaperManager.getInstance(getContext());
              try {
                  myWallpaperManager.setBitmap(bitmap);

              } catch (IOException e) {
                  e.printStackTrace();
              }
          }

        holder.mIvThumb.setImageResource(R.drawable.ic_gf_default_photo);
        Drawable defaultDrawable = mActivity.getResources().getDrawable(R.drawable.ic_gf_default_photo);
        GalleryFinal.getCoreConfig().getImageLoader().displayImage(mActivity, path, holder.mIvThumb, defaultDrawable, mRowWidth, mRowWidth);
        holder.mView.setAnimation(null);
        if (GalleryFinal.getCoreConfig().getAnimation() > 0) {
            holder.mView.setAnimation(AnimationUtils.loadAnimation(mActivity, GalleryFinal.getCoreConfig().getAnimation()));
        }
        holder.mIvCheck.setImageResource(GalleryFinal.getGalleryTheme().getIconCheck());
        if (GalleryFinal.getFunctionConfig().isMutiSelect()) {
            holder.mIvCheck.setVisibility(View.VISIBLE);
            if (mSelectList.contains(photoInfo)) {
                holder.mIvCheck.setBackgroundColor(GalleryFinal.getGalleryTheme().getCheckSelectedColor());
            } else {
                holder.mIvCheck.setBackgroundColor(GalleryFinal.getGalleryTheme().getCheckNornalColor());
            }
        } else {
            holder.mIvCheck.setVisibility(View.GONE);
        }

}


private void setHeight(final View convertView) {
    int height = mScreenWidth / 3 - 8;
    convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
}

public static class PhotoViewHolder extends ViewHolderAdapter.ViewHolder {

    public GFImageView mIvThumb;
    public ImageView mIvCheck;
    View mView;
    public PhotoViewHolder(View view) {
        super(view);
        mView = view;
        mIvThumb = (GFImageView) view.findViewById(R.id.iv_thumb);
        mIvCheck = (ImageView) view.findViewById(R.id.iv_check);
    }
}

}

它使用的地方是:

 mCurPhotoList = new ArrayList<>();
            mPhotoListAdapter = new PhotoListAdapter(this, mCurPhotoList, mSelectPhotoList, mScreenWidth);
            mGvPhotoList.setAdapter(mPhotoListAdapter);

如何让壁纸无限期地改变?

0 个答案:

没有答案