Android Parse ImageView不显示某些图像

时间:2015-02-23 09:29:48

标签: android parse-platform android-parsequeryadapter

在我的Android应用程序中,我通过相机意图获取图片并将其保存到Parse.com并使用ParseImageView将其显示在另一个活动中。我遇到的问题是当我在模拟器中尝试代码时,它工作正常,但在三星Galaxy S4 KitKat 4.4.2上图片没有加载,我无法找到原因。当我从模拟器拍摄照片时,在S4中加载了模拟相机ParseImageView。图片保存得很好,因为我可以在PC上的Parse.com界面上看到它们。它是关于我的代码还是Parse还是它可能是设备?

自定义ParseQueryAdapter

public class CustomImageAdapter extends ParseQueryAdapter<ParseObject> {
String tableName,columnName,whereColumn,whereValue;

private static final int LOW_DPI_STATUS_BAR_HEIGHT = 19;
private static final int MEDIUM_DPI_STATUS_BAR_HEIGHT = 25;
private static final int HIGH_DPI_STATUS_BAR_HEIGHT = 38;




public CustomImageAdapter(Context context, final String tableName, final String columnName, final String whereColumn, final String whereValue) {
    super(context, new QueryFactory<ParseObject>() {
        public ParseQuery create() {

            ParseQuery query = new ParseQuery(tableName);
            query.setLimit(1000);
            query.orderByAscending(columnName);
            query.whereEqualTo(whereColumn,whereValue);
            return query;
        }
    });
    this.tableName=tableName;
    this.columnName=columnName;
    this.whereColumn=whereColumn;
    this.whereValue=whereValue;
}

// Customize the layout by overriding getItemView
@Override
public View getItemView(ParseObject object, View v, ViewGroup parent) {
    if (v == null) {
        v = View.inflate(getContext(), R.layout.lay_custom_image_adapter, null);
    }

    super.getItemView(object, v, parent);
    ParseImageView image = (ParseImageView) v.findViewById(R.id.icon);

    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);

    int statusBarHeight;

    switch (displayMetrics.densityDpi) {
        case DisplayMetrics.DENSITY_HIGH:
            statusBarHeight = HIGH_DPI_STATUS_BAR_HEIGHT;
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
            break;
        case DisplayMetrics.DENSITY_LOW:
            statusBarHeight = LOW_DPI_STATUS_BAR_HEIGHT;
            break;
        default:
            statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
    }


    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y-(statusBarHeight*9);
    Log.d("Test", statusBarHeight + "");

    LinearLayout.LayoutParams layParam=new LinearLayout.LayoutParams(width,height);

    image.setLayoutParams(layParam);

    if(image.getRotation()!=90){

        image.setRotation(90);
    }
    final ParseFile photoFile = object.getParseFile("file");

    if (photoFile != null) {
       image.setParseFile(photoFile);
        image.loadInBackground(new GetDataCallback() {
            @Override
            public void done(byte[] data, ParseException e) {
                // nothing to do
                if(e!=null){
                    Toast.makeText(getContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
                }
                else{

                    Toast.makeText(getContext(),"e=null",Toast.LENGTH_SHORT).show();

                }
            }
        });
    }
    else{

        Toast.makeText(getContext(),"photofile=null",Toast.LENGTH_SHORT).show();

    }

    return v;
}

方式

public void loadImage(){


    customImageAdapter=new CustomImageAdapter(getActivity().getApplicationContext(),tableName,columnName,whereColumn,whereValue);
    customImageAdapter.setPaginationEnabled(false);
    customImageAdapter.loadObjects();
    customImageAdapter.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<ParseObject>() {
        @Override
        public void onLoading() {

            mProgressDialog= new ProgressDialog(getActivity());
            mProgressDialog.setTitle("Loading");
            mProgressDialog.setMessage("Please Wait");
            mProgressDialog.setIndeterminate(false);

            mProgressDialog.show();
        }

        @Override
        public void onLoaded(List<ParseObject> parseObjects, Exception e) {
            if(e!=null) {
                Log.d("Test", e.getMessage());
            }
            mProgressDialog.dismiss();
        }

    });
    npLvPreview.setAdapter(customImageAdapter);


}

另一件事是ProgressDialog也不会在模拟器和设备上显示。

0 个答案:

没有答案