应用程序在Samsung Galaxy Ace上运行不正常

时间:2013-08-28 13:59:13

标签: android

我已经制作了一个在Samsung Galaxy Ace上运行不正常的应用程序。我的问题是,当我试图从另一个活动的对话框中调用特定活动时,它不起作用。虽然我能够打电话给剩下的来自同一活动的活动。我无法理解它背后的问题是什么。

请帮帮我。 感谢。

我的通话活动代码是:

public void onClick(View v) 
{
  if(isCollageFrameSelected)
  {
    EditImageActivity.this.progress = ProgressDialog.show(EditImageActivity.this, "", 
"Loading Collage Frames...", true); 
    EditImageActivity.this.frameDialog.dismiss();   
    new Thread(new Runnable() {

                    public void run() 
                    {
                        Intent localIntent = new Intent(EditImageActivity.this, PhotoCollageActivity.class);
                        localIntent.putExtra(Constants.LAYOUT_ID , layoutId);
                        localIntent.putExtra(Constants.IMAGE_COUNT, imgCount);
                        localIntent.putExtra(Constants.MYBITMAP, selectedBitmap);
                        startActivity(localIntent);
                        EditImageActivity.this.progress.dismiss();
                    }
              }).start();  
}

我的被叫活动代码是:

public class PhotoCollageActivity extends FragmentActivity
    implements View.OnTouchListener, View.OnLongClickListener
{
  private ColorFilter filter;
  private int imgCount = 3;
  private int imgId;
  private List<Integer> imgIds;
  private int lastAction = 0;
  private Map<Integer, Matrix> matrix = new HashMap<Integer, Matrix>();
  private int mode = 0;
  private int moveActions = 0;
  private Map<Integer, Float> oldDist = new HashMap<Integer, Float>();
  private Map<Integer, Integer> patterns;
  private ProgressDialog pd;
  private Bitmap photo;
  private Map<String, PointF> points = new HashMap<String, PointF>();
  private Map<Integer, Matrix> savedMatrix = new HashMap<Integer, Matrix>();    
  private Map<Integer, Border> bordersMap = new HashMap<Integer, Border>();
  private DialogFragment df;
  Dialog dialog;

  private Handler handler = new Handler()
  {
     public void handleMessage(Message paramAnonymousMessage)
     {
        PhotoCollageActivity.this.setImage();
        PhotoCollageActivity.this.pd.dismiss();
     }
  };

  private Handler handlerDialog = new Handler()
  {
      public void handleMessage(Message paramAnonymousMessage)
      {
         try
         {
            PhotoCollageActivity.this.df.dismiss();
            return;
         }
         catch (Exception localException)
         {
            localException.printStackTrace();
         }
      }
  };

private void dumpEvent(MotionEvent paramMotionEvent)
{
String[] arrayOfString = { "DOWN", "UP", "MOVE", "CANCEL", 
"OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" };
StringBuilder localStringBuilder = new StringBuilder();
int i = paramMotionEvent.getAction();
int j = i & 0xFF;
localStringBuilder.append("event ACTION_").append(arrayOfString[j]);
if ((j == 5) || (j == 6))
{
localStringBuilder.append("(pid ").append(i >> 8);
localStringBuilder.append(")");
}
localStringBuilder.append("[");
for (int k = 0; ; k++)
{
if (k >= paramMotionEvent.getPointerCount())
{
localStringBuilder.append("]");
return;
}
localStringBuilder.append("#").append(k);
localStringBuilder.append("(pid ").append(paramMotionEvent.getPointerId(k));
localStringBuilder.append(")=").append((int)paramMotionEvent.getX(k));
localStringBuilder.append(",").append((int)paramMotionEvent.getY(k));
if (k + 1 < paramMotionEvent.getPointerCount())
localStringBuilder.append(";");
}
}


private Map<Integer, Border> getBordersMap()
{
HashMap<Integer, Border> localHashMap = new HashMap<Integer, Border>();
localHashMap.put(Integer.valueOf(R.id._1_img ), new Border(R.id._1_border));
localHashMap.put(Integer.valueOf(R.id._2_img), new Border(R.id._2_border));
localHashMap.put(Integer.valueOf(R.id._3_img), new Border(R.id._3_border));
localHashMap.put(Integer.valueOf(R.id._4_img), new Border(R.id._4_border));
return localHashMap;
}

private List<Integer> getImageViewIds()
{
ArrayList<Integer> localArrayList = new ArrayList<Integer>();
localArrayList.add(Integer.valueOf(R.id._1_img));
localArrayList.add(Integer.valueOf(R.id._2_img));
localArrayList.add(Integer.valueOf(R.id._3_img));
localArrayList.add(Integer.valueOf(R.id._4_img));
return localArrayList;
}

public static Map<Integer, Integer> getPatterns()
{
HashMap<Integer, Integer> localHashMap = new HashMap<Integer, Integer>();
localHashMap.put(Integer.valueOf(R.id. pattern_01 ),Integer.valueOf(R.drawable.tile_christ_1));      
localHashMap.put(Integer.valueOf(R.id.pattern_02), Integer.valueOf(R.drawable.tile_christ_2));
localHashMap.put(Integer.valueOf(R.id.pattern_03), Integer.valueOf(R.drawable.tile_christ_3 ));
localHashMap.put(Integer.valueOf(R.id.pattern_04), Integer.valueOf(R.drawable.tile_christ_4));
localHashMap.put(Integer.valueOf(R.id.pattern_05), Integer.valueOf(R.drawable.tile_christ_5));
localHashMap.put(Integer.valueOf(R.id.pattern_06), Integer.valueOf(R.drawable.tile_christ_6));
localHashMap.put(Integer.valueOf(R.id.pattern_07), Integer.valueOf(R.drawable.tile_christ_7));
localHashMap.put(Integer.valueOf(R.id.pattern_08), Integer.valueOf(R.drawable.tile_christ_8));
localHashMap.put(Integer.valueOf(R.id.pattern_09), Integer.valueOf(R.drawable.tile_christ_9));
localHashMap.put(Integer.valueOf(R.id.pattern_1), Integer.valueOf(R.drawable.p1));
localHashMap.put(Integer.valueOf(R.id.pattern_2), Integer.valueOf(R.drawable.p2));
localHashMap.put(Integer.valueOf(R.id.pattern_3), Integer.valueOf(R.drawable.p3));
localHashMap.put(Integer.valueOf(R.id.pattern_4), Integer.valueOf(R.drawable.p4));
localHashMap.put(Integer.valueOf(R.id.pattern_5), Integer.valueOf(R.drawable.p5));
localHashMap.put(Integer.valueOf(R.id.pattern_6), Integer.valueOf(R.drawable.p6));
localHashMap.put(Integer.valueOf(R.id.pattern_7), Integer.valueOf(R.drawable.p7));
localHashMap.put(Integer.valueOf(R.id.pattern_8), Integer.valueOf(R.drawable.p8));
localHashMap.put(Integer.valueOf(R.id.pattern_9), Integer.valueOf(R.drawable.p9));
localHashMap.put(Integer.valueOf(R.id.pattern_10), Integer.valueOf(R.drawable.p10));
localHashMap.put(Integer.valueOf(R.id.pattern_11), Integer.valueOf(R.drawable.p11));
localHashMap.put(Integer.valueOf(R.id.pattern_12), Integer.valueOf(R.drawable.p12));
localHashMap.put(Integer.valueOf(R.id.pattern_13), Integer.valueOf(R.drawable.p13));
localHashMap.put(Integer.valueOf(R.id.pattern_14), Integer.valueOf(R.drawable.p14));
localHashMap.put(Integer.valueOf(R.id.pattern_15), Integer.valueOf(R.drawable.p15));
localHashMap.put(Integer.valueOf(R.id.pattern_16), Integer.valueOf(R.drawable.p16));
localHashMap.put(Integer.valueOf(R.id.pattern_17), Integer.valueOf(R.drawable.p17));
localHashMap.put(Integer.valueOf(R.id.pattern_18), Integer.valueOf(R.drawable.p18));
localHashMap.put(Integer.valueOf(R.id.pattern_19), Integer.valueOf(R.drawable.p19));
localHashMap.put(Integer.valueOf(R.id.pattern_20), Integer.valueOf(R.drawable.p20));
localHashMap.put(Integer.valueOf(R.id.pattern_21), Integer.valueOf(R.drawable.p21));
localHashMap.put(Integer.valueOf(R.id.pattern_22), Integer.valueOf(R.drawable.p22));
localHashMap.put(Integer.valueOf(R.id.pattern_23), Integer.valueOf(R.drawable.p23));
localHashMap.put(Integer.valueOf(R.id.pattern_24), Integer.valueOf(R.drawable.p24));
localHashMap.put(Integer.valueOf(R.id.pattern_25), Integer.valueOf(R.drawable.p25));
return localHashMap;
}

private void getPhotoBitmap(String paramString)
{
BitmapFactory.Options localOptions = new BitmapFactory.Options();
localOptions.inJustDecodeBounds = false;
localOptions.inSampleSize = BitmapUtils.calculateInSampleSize(paramString);
try
{
this.photo = BitmapFactory.decodeFile(paramString, localOptions);
return;
}
catch (OutOfMemoryError localOutOfMemoryError)
{
this.photo.recycle();
localOptions.inSampleSize = (1 + localOptions.inSampleSize);
}
}

private void midPoint(PointF paramPointF, MotionEvent paramMotionEvent)
{
float f1 = paramMotionEvent.getX(0) + paramMotionEvent.getX(1);
float f2 = paramMotionEvent.getY(0) + paramMotionEvent.getY(1);
paramPointF.set(f1 / 2.0F, f2 / 2.0F);
}

private void setImage()  
{
((ImageView)findViewById(this.imgId))
.setImageBitmap(ImageHelper.getRoundedCornerBitmap(this.photo, 10));
}

private float spacing(MotionEvent paramMotionEvent)
{
float f1 = paramMotionEvent.getX(0) - paramMotionEvent.getX(1);
float f2 = paramMotionEvent.getY(0) - paramMotionEvent.getY(1);
return (float) java.lang.Math.sqrt(f1 * f1 + f2 * f2);
}

protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN);

this.imgIds = getImageViewIds();
this.bordersMap = getBordersMap();
this.patterns = getPatterns();

Bundle localBundle = getIntent().getExtras();
this.filter = new ColorFilter();
int i = 0;
Iterator<Integer> localIterator;
if ((localBundle != null) && (localBundle.getInt(Constants.LAYOUT_ID) != 0) 
&& (localBundle.getInt(Constants.IMAGE_COUNT) != 0))
{
setContentView(localBundle.getInt(Constants.LAYOUT_ID));
this.imgCount = localBundle.getInt(Constants.IMAGE_COUNT);

while (i < this.imgCount)
{
ImageView localImageView = (ImageView)findViewById(((Integer)this.imgIds.get(i)).intValue());
this.matrix.put(Integer.valueOf(localImageView.getId()), new Matrix());
this.savedMatrix.put(Integer.valueOf(localImageView.getId()), new Matrix());
this.oldDist.put(Integer.valueOf(localImageView.getId()), Float.valueOf(1.0F));
this.points.put("start" + localImageView.getId(), new PointF());
this.points.put("mid" + localImageView.getId(), new PointF());
localImageView.setOnTouchListener(this);
localImageView.setOnLongClickListener(this);
i++;
}
}


if((Bitmap)this.getIntent().getParcelableExtra(Constants.MYBITMAP) != null)
{

((ImageView)findViewById(((Integer)this.imgIds.get(new Random().nextInt(2)))))
.setImageBitmap(ImageHelper.getRoundedCornerBitmap((Bitmap)this.getIntent()
.getParcelableExtra(Constants.MYBITMAP), 10));
}

((ImageView)findViewById(R.id.shareBtn)).setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
Bitmap localBitmap = BitmapUtils.loadBitmapFromView(PhotoCollageActivity.this
.findViewById(R.id.mashup_container));
String str =  BitmapUtils.saveBitmap(localBitmap, "LoveFrames_" 
+ new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.US)
.format(new Date()).toString(), getContentResolver());
Toast.makeText(PhotoCollageActivity.this, "image has been saved in gallery at" +str, 
Toast.LENGTH_LONG).show();
localBitmap.recycle();
Intent localIntent = new Intent("android.intent.action.SEND");
localIntent.setType("image/jpeg");
localIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(new File(str)));
localIntent.addFlags(1);
localIntent.putExtra("android.intent.extra.SUBJECT", "Check out photo collage");
localIntent.putExtra("android.intent.extra.TEXT", "from photocollage");
PhotoCollageActivity.this.startActivity(localIntent);

}
});

//////////////////   set tiles as background of layout  /////////////////////////////// 
localIterator = this.patterns.keySet().iterator();
while (localIterator.hasNext())
{
findViewById(((Integer)localIterator.next()).intValue())
.setOnClickListener(new View.OnClickListener()
{
@SuppressWarnings("deprecation")
public void onClick(View paramAnonymousView)
{
Bitmap localBitmap = BitmapFactory.decodeResource(PhotoCollageActivity.this.getResources(), 
(Integer)PhotoCollageActivity.this.patterns.
get(Integer.valueOf(paramAnonymousView.getId()))).intValue());

BitmapDrawable localBitmapDrawable = 
new BitmapDrawable(PhotoCollageActivity.this.getResources(), localBitmap);
localBitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
PhotoCollageActivity.this.findViewById(R.id.mashup_container)
.setBackgroundDrawable(localBitmapDrawable);
}
});
}
} 
/////////////////////////////////////////////////////////////////////////////////////////////////
public boolean onLongClick(View paramView)
{
FragmentManager localFragmentManager = getSupportFragmentManager();
new DialogKolaz().show(localFragmentManager, "fragment_edit_name");
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
{
ImageView localImageView = (ImageView)paramView;
dumpEvent(paramMotionEvent);
switch (MotionEvent.ACTION_MASK & paramMotionEvent.getAction())
{
case 3:
case 4:
case MotionEvent.ACTION_DOWN:
((Matrix)this.savedMatrix.get(Integer.valueOf(paramView.getId())))
.set((Matrix)this.matrix.get(Integer.valueOf(paramView.getId())));
((PointF)this.points.get("start" + paramView.getId()))
          .set(paramMotionEvent.getX(), paramMotionEvent.getY());
this.mode = Constants.DRAG;
this.lastAction = 0;
break;

case MotionEvent.ACTION_POINTER_DOWN:
this.lastAction = -1;
this.oldDist.put(Integer.valueOf(paramView.getId()), Float.valueOf(spacing(paramMotionEvent)));
if (((Float)this.oldDist.get(Integer.valueOf(paramView.getId()))).floatValue() > 10.0F)
{
((Matrix)this.savedMatrix.get(Integer.valueOf(paramView.getId())))
.set((Matrix)this.matrix.get(Integer.valueOf(paramView.getId())));
midPoint((PointF)this.points.get("mid" + paramView.getId()), paramMotionEvent);
this.mode = Constants.ZOOM;
}
break;

case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
if (this.lastAction < 4)
{
FragmentManager localFragmentManager = getSupportFragmentManager();
this.df = new DialogKolaz();
this.df.setStyle(2, 0);
this.df.show(localFragmentManager, "fragment_edit_name");
this.lastAction = -1;
this.imgId = paramView.getId();
}
this.mode = Constants.NONE;
break;
case MotionEvent.ACTION_MOVE:
this.lastAction = (1 + this.lastAction);
this.moveActions = (1 + this.moveActions);
if (this.mode == Constants.DRAG)
{
((Matrix)this.matrix.get(Integer.valueOf(paramView.getId())))
.set((Matrix)this.savedMatrix.get(Integer.valueOf(paramView.getId())));
((Matrix)this.matrix.get(Integer.valueOf(paramView.getId())))
.postTranslate(paramMotionEvent.getX() - ((PointF)this.points
.get("start" + paramView.getId())).x, paramMotionEvent.getY() 
- ((PointF)this.points.get("start" + paramView.getId())).y);
}
else if (this.mode == Constants.ZOOM )
{
float f1 = spacing(paramMotionEvent);
if (f1 > 10.0F)
{
((Matrix)this.matrix.get(Integer.valueOf(paramView.getId())))
.set((Matrix)this.savedMatrix.get(Integer.valueOf(paramView.getId())));
float f2 = f1 / ((Float)this.oldDist.get(Integer.valueOf(paramView.getId()))).floatValue();
((Matrix)this.matrix.get(Integer.valueOf(paramView.getId())))
.postScale(f2, f2, ((PointF)this.points.get("mid" + paramView.getId())).x, 
((PointF)this.points.get("mid" + paramView.getId())).y);
}
}
break;
}
localImageView.setImageMatrix((Matrix)this.matrix.get(Integer.valueOf(paramView.getId())));
return true;
}

////////////////////////////////////////////////////////////////////////////////// 
@SuppressLint("ValidFragment")
private class DialogKolaz extends DialogFragment
{
public DialogKolaz()
{
}

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode,data);
if (resultCode != RESULT_OK){
PhotoCollageActivity.this.handlerDialog.sendEmptyMessage(0);
return;
}
try
{
if ((requestCode == Constants.APP_KOLAZ_GALLERY) && (resultCode == RESULT_OK ))
{
Uri localUri = data.getData();
PhotoCollageActivity.this.handlerDialog.sendEmptyMessage(0);
String[] arrayOfString = { "_data" };
Cursor localCursor = PhotoCollageActivity.this.getContentResolver()
.query(localUri, arrayOfString, null, null, null);
localCursor.moveToFirst();
String str = localCursor.getString(localCursor.getColumnIndex(arrayOfString[0]));
localCursor.close();
PhotoCollageActivity.this.getPhotoBitmap(str);
}
else if ((requestCode == Constants.APP_KOLAZ_CAMERA) && (resultCode == RESULT_OK))
{
PhotoCollageActivity.this.pd = ProgressDialog.show(PhotoCollageActivity.this, 
"Working", "Please wait...", true, false);
new PhotoCollageActivity.PhotoThread().start();
}
PhotoCollageActivity.this.setImage();
}
catch (Exception localException)
{
localException.printStackTrace();
}
}

/////////////////////////////////////////////////////////////////////////////////////////  
public View onCreateView(LayoutInflater paramLayoutInflater, 
ViewGroup paramViewGroup, Bundle paramBundle)
{
View localView = paramLayoutInflater.inflate(R.layout.choose_dialog, paramViewGroup,false);

ImageView localImageView1 = (ImageView)localView.findViewById(R.id.gallery);
ImageView localImageView2 = (ImageView)localView.findViewById(R.id.camera);
ImageView localImageView3 = (ImageView)localView.findViewById(R.id.rotate);
ImageView localImageView4 = (ImageView)localView.findViewById(R.id.borders);
ImageView localImageView5 = (ImageView)localView.findViewById(R.id.imgeffect);

localImageView1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
Intent localIntent = new Intent("android.intent.action.PICK", 
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
PhotoCollageActivity.DialogKolaz.this.startActivityForResult(localIntent, 
Constants.APP_KOLAZ_GALLERY);
}
});

localImageView2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE");
localIntent.putExtra("output", Uri.fromFile(new File("/sdcard/tmp.file")));
PhotoCollageActivity.DialogKolaz.this.startActivityForResult(localIntent, 
Constants.APP_KOLAZ_CAMERA);
}
});

localImageView3.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
Matrix localMatrix = new Matrix();
localMatrix.postRotate(90.0F);
ImageView localImageView = (ImageView)PhotoCollageActivity.this.
findViewById(PhotoCollageActivity.this.imgId);
PhotoCollageActivity.this.photo = ( (BitmapDrawable)localImageView.getDrawable() ).getBitmap();
PhotoCollageActivity.this.photo = Bitmap.createBitmap(PhotoCollageActivity.this.photo, 
0, 0, PhotoCollageActivity.this.photo.getWidth(), PhotoCollageActivity.this.photo.getHeight(), 
localMatrix, true);
localImageView.setImageBitmap(PhotoCollageActivity.this.photo);
PhotoCollageActivity.this.handlerDialog.sendEmptyMessage(0);
}
});

localImageView4.setOnClickListener(new View.OnClickListener() 
{
public void onClick(View paramAnonymousView)
{
Border localBorder = (Border)PhotoCollageActivity.this.bordersMap
.get(Integer.valueOf(PhotoCollageActivity.this.imgId));
View localView = PhotoCollageActivity.this.findViewById(localBorder.id);
if (localBorder.visible)
{
localView.setBackgroundResource(R.drawable.rounded_transparent);
localBorder.visible = false;
}
else
{
PhotoCollageActivity.this.handlerDialog.sendEmptyMessage(0);
localView.setBackgroundResource(R.drawable.rounded);
localBorder.visible = true;
}
PhotoCollageActivity.this.handlerDialog.sendEmptyMessage(0);
}
});

localImageView5.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
ImageView localImageView = (ImageView)PhotoCollageActivity.this.
findViewById(PhotoCollageActivity.this.imgId);
int choose = new Random().nextInt(10);
if(choose == 0)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(350 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 1)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(400 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 2)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(500 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 3)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(300 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 4)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(150 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 5)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(175 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 6)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(125 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 7)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(100 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 8)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(75 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}
if(choose == 9)
{
PhotoCollageActivity.this.filter = EffectUtils.adjustHue(50 - 255);
localImageView.setColorFilter(PhotoCollageActivity.this.filter);
}

}
});

return localView;
}
}
//////////////////////////////////////////////////////////////////////////////////////
private class PhotoThread extends Thread
{
private PhotoThread()
{
}

public void run()
{
PhotoCollageActivity.this.getPhotoBitmap("/sdcard/tmp.file");
PhotoCollageActivity.this.handler.sendEmptyMessage(0);
}
}
}

0 个答案:

没有答案