public class PreviewActivity extends Activity {

    private ImageView previewIV;
    private final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
    private String path;
    private boolean crop = true;
    private boolean resample = true;
    private ProgressDialog pd;

    OnClickListener processOnClickListener = new OnClickListener() {
        public void onClick(View v) {
            try {
                createProgressDialog();
                pd.show();
                new Segement(PreviewActivity.this, pd).execute(path);
            } catch (IOException e) {
            }
        }
    };

    private void createProgressDialog() {
        pd = new ProgressDialog(PreviewActivity.this);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setTitle("Extract ID");
        pd.setMessage("Processing...");
        pd.setIcon(R.drawable.ic_launcher);
        pd.setProgress(0);
        pd.setCancelable(false);
    }

    private OnClickListener backOnClickListener = new OnClickListener() {
        public void onClick(View v) {
            startActivityForResult(
                    new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
                            MediaStore.EXTRA_OUTPUT,
                            Uri.fromFile(new File(path))),
                    CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        }
    };

    protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
                previewIV.setImageBitmap(BitmapFactory.decodeFile(path));
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preview);

        path = getIntent().getExtras().getString("path");
//        Log.d("path", path);
      //  path = "/sdcard/Pictures/MyCameraApp/IMG01.jpg";

        previewIV = (ImageView) findViewById(R.id.previewPicID);
        previewIV.setImageBitmap(AndroidImage.decodeSampledBitmapFromSDcard(
                path, 1000, 1000));
        // previewIV.setImageBitmap(AndroidImage.readImage(path));

        Button process = (Button) findViewById(R.id.processID);
        process.setOnClickListener(processOnClickListener);

        Button back = (Button) findViewById(R.id.back);
        back.setOnClickListener(backOnClickListener);
    }

AndroidImage is a utility class for read write downSample ....

On Tue, Jun 26, 2012 at 10:52 PM, Justin Anderson <[email protected]>wrote:

> Generally sending the whole code won't be beneficial... How about posting
> the code for your activity?
>
>
> Thanks,
> Justin Anderson
> MagouyaWare Developer
> http://sites.google.com/site/magouyaware
>
>
> On Tue, Jun 26, 2012 at 2:25 PM, mahmoud emam <[email protected]>wrote:
>
>> *no each call in different places and the Segment class its my own class
>> that i use it to do extract Numbers from an image
>> I can send you the whole code if you want
>> *
>>
>> On Tue, Jun 26, 2012 at 10:15 PM, Justin Anderson 
>> <[email protected]>wrote:
>>
>>> How many times are you calling CreateProgressDialog()?  It is called in
>>> your onClick() method and in onPreExecute()....
>>>
>>> Also, what does the Segement class do?
>>>
>>>
>>> Thanks,
>>> Justin Anderson
>>> MagouyaWare Developer
>>> http://sites.google.com/site/magouyaware
>>>
>>>
>>> On Tue, Jun 26, 2012 at 12:48 PM, mahmoud emam <[email protected]>wrote:
>>>
>>>> Event handler that call the AsyncTask
>>>>
>>>>
>>>> OnClickListener processOnClickListener = new OnClickListener() {
>>>>         public void onClick(View v) {
>>>>             try {
>>>>                 createProgressDialog();
>>>>                 pd.show();
>>>>                 new Segement(PreviewActivity.this, pd).execute(path);
>>>>             } catch (IOException e) {
>>>>             }
>>>>         }
>>>>     };
>>>>
>>>> Full back trace
>>>>
>>>> 06-26 20:45:58.159: E/WindowManager(8663): Activity
>>>> com.android.grad.LoginActivity has leaked window
>>>> com.android.internal.policy.impl.PhoneWindow$DecorView@2be6a248 that
>>>> was originally added here
>>>> 06-26 20:45:58.159: E/WindowManager(8663): android.view.WindowLeaked:
>>>> Activity com.android.grad.LoginActivity has leaked window
>>>> com.android.internal.policy.impl.PhoneWindow$DecorView@2be6a248 that
>>>> was originally added here
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.view.Window$LocalWindowManager.addView(Window.java:537)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.app.Dialog.show(Dialog.java:278)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.app.ProgressDialog.show(ProgressDialog.java:116)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.app.ProgressDialog.show(ProgressDialog.java:99)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.app.ProgressDialog.show(ProgressDialog.java:94)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> com.android.grad.LoginTask.onPreExecute(LoginTask.java:24)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.os.AsyncTask.execute(AsyncTask.java:511)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> com.android.grad.LoginActivity$1.onClick(LoginActivity.java:35)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.view.View.performClick(View.java:3527)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.view.View$PerformClick.run(View.java:14234)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.os.Handler.handleCallback(Handler.java:605)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.os.Handler.dispatchMessage(Handler.java:92)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.os.Looper.loop(Looper.java:137)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> android.app.ActivityThread.main(ActivityThread.java:4441)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> java.lang.reflect.Method.invokeNative(Native Method)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> java.lang.reflect.Method.invoke(Method.java:511)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
>>>> 06-26 20:45:58.159: E/WindowManager(8663):     at
>>>> dalvik.system.NativeStart.main(Native Method)
>>>> 06-26 20:45:58.279: D/dalvikvm(8663): GC_CONCURRENT freed 265K, 4% free
>>>> 9332K/9671K, paused 10ms+3ms
>>>> 06-26 20:45:58.319: D/AndroidRuntime(8663): Shutting down VM
>>>> 06-26 20:45:58.329: W/dalvikvm(8663): threadid=1: thread exiting with
>>>> uncaught exception (group=0x2b542210)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663): FATAL EXCEPTION: main
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):
>>>> java.lang.IllegalArgumentException: View not attached to window manager
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:587)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:324)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:151)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.app.Dialog.dismissDialog(Dialog.java:321)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.app.Dialog$1.run(Dialog.java:119)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.app.Dialog.dismiss(Dialog.java:306)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> com.android.grad.LoginTask.onPostExecute(LoginTask.java:39)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> com.android.grad.LoginTask.onPostExecute(LoginTask.java:1)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.os.AsyncTask.finish(AsyncTask.java:602)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.os.AsyncTask.access$600(AsyncTask.java:156)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.os.Handler.dispatchMessage(Handler.java:99)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.os.Looper.loop(Looper.java:137)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> android.app.ActivityThread.main(ActivityThread.java:4441)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> java.lang.reflect.Method.invokeNative(Native Method)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> java.lang.reflect.Method.invoke(Method.java:511)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
>>>> 06-26 20:45:58.329: E/AndroidRuntime(8663):     at
>>>> dalvik.system.NativeStart.main(Native Method)
>>>>
>>>>
>>>> The error thrown here
>>>>
>>>> @Override
>>>>     protected void onPreExecute() {
>>>>         pd = ProgressDialog.show(activity, "Signing in",
>>>>                 "Please wait while we are signing you in..");
>>>>
>>>>     }
>>>>
>>>> On Tue, Jun 26, 2012 at 5:52 PM, G. Blake Meike 
>>>> <[email protected]>wrote:
>>>>
>>>>> Mahmoud,
>>>>>   I'd be interested in pursuing this, if you are still having the
>>>>> problem.  Would you:
>>>>> - Post the code for the anonymous onClick handler, in which the
>>>>> exception is being thrown?
>>>>> - Post the entire exception that is the problem
>>>>>
>>>>> Thanks,
>>>>> G. Blake Meike
>>>>> Marakana
>>>>>
>>>>> The second edition of Programming Android is now on-line:
>>>>> http://shop.oreilly.com/product/0636920023005.do
>>>>>
>>>>> On Monday, June 25, 2012 9:19:41 AM UTC-7, Mahmoud Emam wrote:
>>>>>>
>>>>>> 06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> com.android.grad.PreviewActivi**ty$1.onClick(PreviewActivity.j**ava:36)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> android.view.View.performClick**(View.java:3527)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> android.view.View$PerformClick**.run(View.java:14234)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> android.os.Handler.handleCallb**ack(Handler.java:605)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> android.os.Handler.dispatchMes**sage(Handler.java:92)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> android.os.Looper.loop(Looper.**java:137)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> android.app.ActivityThread.mai**n(ActivityThread.java:4441)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> java.lang.reflect.Method.invok**eNative(Native Method)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> java.lang.reflect.Method.invok**e(Method.java:511)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> com.android.internal.os.Zygote**Init$MethodAndArgsCaller.run(Z**ygoteInit.java:784)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> com.android.internal.os.Zygote**Init.main(ZygoteInit.java:551)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:02.596: E/WindowManager(29217):     at 
>>>>>> dalvik.system.NativeStart.main**(Native Method)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.186: I/Process(29217): Sending signal. PID: 29217 
>>>>>> SIG: 9
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.566: D/TextLayoutCache(29339): Using debug level: 0 - 
>>>>>> Debug Enabled: 0
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.606: D/libEGL(29339): loaded 
>>>>>> /system/lib/egl/libGLES_**android.so
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.606: D/libEGL(29339): loaded 
>>>>>> /system/lib/egl/libEGL_**adreno200.so
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.636: D/libEGL(29339): loaded 
>>>>>> /system/lib/egl/libGLESv1_CM_**adreno200.so
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.636: D/dalvikvm(29339): GC_CONCURRENT freed 117K, 3% 
>>>>>> free 9125K/9351K, paused 4ms+17ms
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.636: D/libEGL(29339): loaded 
>>>>>> /system/lib/egl/libGLESv2_**adreno200.so
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:04.706: D/OpenGLRenderer(29339): Enabling debug mode 0
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:07.326: D/OpenGLRenderer(29339): Flushing caches (mode 0)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:07.326: W/IInputConnectionWrapper(2933**9): 
>>>>>> showStatusIcon on inactive InputConnection
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     06-25 15:03:07.366: D/OpenGLRenderer(29339): Flushing caches (mode 1)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>  I know that this error asked before and i saw the solutions for
>>>>>> that but the solutions don't work with me. and this is my code.
>>>>>>
>>>>>> The error appear on pd.show().
>>>>>>
>>>>>> @Override
>>>>>> protected void onPreExecute() {
>>>>>>     //network.loadData();
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     file = new File(
>>>>>>             Environment
>>>>>>                     
>>>>>> .getExternalStoragePublicDirec**tory(Environment.DIRECTORY_**PICTURES),
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             "MyCameraApp" + File.separator + "project");
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     createProgressDialog();
>>>>>>     pd.show();
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> protected Boolean doInBackground(String... params) {
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     try {
>>>>>>         crop = new Crop(params[0]);
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>         crop.cropID();
>>>>>>         croppedID = crop.getId();
>>>>>>         publishProgress(2);
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     } catch (IOException e) {
>>>>>>     }
>>>>>>
>>>>>>     segmentNumbers();
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     return true;
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> protected void onProgressUpdate(Integer... values) {
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     pd.incrementProgressBy(values[**0]);
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> protected void onPostExecute(Boolean result) {
>>>>>>     pd.dismiss();
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     Toast.makeText(activity, "Processing Done", 
>>>>>> Toast.LENGTH_LONG).show();
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> }
>>>>>>
>>>>>> private void createProgressDialog() {
>>>>>>     pd = new ProgressDialog(activity);
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     pd.setProgressStyle(ProgressDi**alog.STYLE_HORIZONTAL);
>>>>>>     pd.setTitle("Extract ID");
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     pd.setMessage("Processing...")**;
>>>>>>     pd.setIcon(R.drawable.ic_**launcher);
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>     pd.setProgress(0);
>>>>>>     pd.setCancelable(false);
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>  onpreExecution method :- i am showing my dialog. doInBackGround
>>>>>> method :- I execute my segmentNumber() which used to segement picture.
>>>>>> onPostExecution method :- I am dismissing my dialog.
>>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Android Developers" group.
>>>>> To post to this group, send email to
>>>>> [email protected]
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected]
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/android-developers?hl=en
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to
>>>> [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/android-developers?hl=en
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to