0

在我的 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 也不显示在模拟器和设备上。

4

0 回答 0