即使在返回或重新启动应用程序后单击它也会禁用按钮

时间:2015-09-23 10:34:16

标签: android api listview signature sign

我正在制作和申请,登录后我得到多个“订单”列表,如订单1,订单2,订单3等,具体取决于来自API的数据。在单一订单中有详细信息,如订单号,纬度经度等等。我希望在特定订单上点击ex。就像我点击订单号1(每个订单号都是唯一的)页面将重定向下一页有一个名为“签名”的按钮后点击它将重定向到有三个选项的下一页。选项是这些确认(按钮),挑选(按钮), 交付(按钮)。在这些按钮事件上,我正在调用一个页面,我正在签名并在服务器上发送该签名。(直到现在我已完成所有编码并且工作正常)。我想要的是一旦签名完成,按钮应该被禁用特定订单没有前。就像我点击了1号订单的确认按钮并完成了签名并保存了它。对于下次没有1的订单,应该禁用已确认的按钮。

流程就在这里 订单号为no订单no1,订单号为no3,订货号为no3等 点击订单号1后 具有按钮名称签名的下一个布局。在单击签名按钮之后。它将发送到下一页有3个按钮。按钮被确认,挑选和交付。 点击确认按钮 将弹出一个屏幕并完成签名,并在服务器上发送该签名。 我想要 我想要的东西是一旦签名保存并发送到服务器,确认按钮应该被禁用与其他按钮相同的功能,如选择按钮和交付按钮。对于订单号1,应禁用这些按钮。

我附上签名功能正在运行的签名页代码。

签名代码页面有3个按钮“已确认,已选中,已发送

package com.example.demo_kaizen;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class popp_upp extends Activity {

    Button confirm, Delivered,pciked,done_image,clear_image;

    final String odddr_id=Staticcontent._order_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pop_up);
        StrictMode.enableDefaults();
        done_image=(Button) findViewById(R.id.DoneButton);
        clear_image=(Button) findViewById(R.id.ClearButton);


        //Toast.makeText(getApplicationContext(),i_d,2000 ).show();


        //Toast.makeText(getApplicationContext(), Staticcontent.driver_id, 2000).show();

        if (android.os.Build.VERSION.SDK_INT > 8) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                    .permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }









        // Delivered=(Button) findViewById(R.id.tvDelivered);
        confirm = (Button) findViewById(R.id.tvConfirmed);



        confirm.setOnClickListener(new OnClickListener() {


            @Override
            public void onClick(View v) {
                Staticcontent._confirm_sign = "confirmed";
                Intent intent = new Intent(popp_upp.this, Esignature.class);
                startActivity(intent);
                confirm.setVisibility(View.GONE);
            }
        });
    }



/*=====================================================
code for delivry sign*/



    public void delvi(View v) {
        Staticcontent._confirm_sign = "delivered";
        Intent intent = new Intent(popp_upp.this, Esignature.class);
        startActivity(intent);
    }



/*=====================================================
code for picked sign*/

    public void picked(View v) {
        Staticcontent._confirm_sign = "picked";
        Intent intent = new Intent(popp_upp.this, Esignature.class);
        startActivity(intent);
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
    //  super.onBackPressed();

    Intent intent=new Intent(popp_upp.this,Itemm_dashboard.class);
    startActivity(intent);
    }

}

签名代码保存并发送至服务器

package com.example.demo_kaizen;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGestureListener;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

public class Esignature extends Activity {

    String SERVER_URL = "http://showcase.pcubelive.com/kaizen/app_api/signature_api.php";
    String attachmentName = "image";
    String attachmentFileName = "image.jpg";
    String crlf = "\r\n";
    String twoHyphens = "--";
    String boundary = "*****";

    GestureOverlayView gestureView;
    String path;
    File file;
    Bitmap bitmap;
    public boolean gestureTouch = false;

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.esign_main);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);

        Button donebutton = (Button) findViewById(R.id.DoneButton);
        donebutton.setText("Done");
        Button clearButton = (Button) findViewById(R.id.ClearButton);
        clearButton.setText("Clear");

        path = Environment.getExternalStorageDirectory() + "/signature.JPEG";
        file = new File(path);
        file.delete();
        gestureView = (GestureOverlayView) findViewById(R.id.signaturePad);
        gestureView.setDrawingCacheEnabled(true);

        gestureView.setAlwaysDrawnWithCacheEnabled(true);
        gestureView.setHapticFeedbackEnabled(false);
        gestureView.cancelLongPress();
        gestureView.cancelClearAnimation();
        gestureView.addOnGestureListener(new OnGestureListener() {

            @Override
            public void onGesture(GestureOverlayView arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onGestureCancelled(GestureOverlayView arg0,
                    MotionEvent arg1) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onGestureEnded(GestureOverlayView arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onGestureStarted(GestureOverlayView arg0,
                    MotionEvent arg1) {
                // TODO Auto-generated method stub
                if (arg1.getAction() == MotionEvent.ACTION_MOVE) {
                    gestureTouch = false;
                } else {
                    gestureTouch = true;
                }
            }
        });

        donebutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                new PostSignature(Esignature.this).execute();
            }
        });

        clearButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                gestureView.invalidate();
                gestureView.clear(true);
                gestureView.clearAnimation();
                gestureView.cancelClearAnimation();
            }
        });
    }

    private class PostSignature extends AsyncTask<Void, Void, Boolean>
    {
        ProgressDialog pDialog = null;

        public PostSignature(Context context)
        {
            pDialog = new ProgressDialog(context);
            pDialog.setCancelable(false);
            pDialog.setMessage("Uploading Signature...");
        }

        @Override
        protected void onPreExecute()
        {
            pDialog.show();
        }

        @Override
        protected Boolean doInBackground(Void... params) {
            try {
                bitmap = Bitmap.createBitmap(gestureView.getDrawingCache());
                File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "sign.jpg");
                FileOutputStream fout = new FileOutputStream(f);
                bitmap.compress(CompressFormat.JPEG, 70, fout);
                fout.close();
                MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                entity.addPart("image", new FileBody(f));

                SharedPreferences mshare = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext());

                entity.addPart("order_id", new StringBody(Staticcontent._order_id));
                entity.addPart("signature_id", new StringBody(Staticcontent._confirm_sign));
                entity.addPart("txt_user_email", new StringBody(mshare.getString("vkey", "vikram")));

                HttpParams httpParameters = new BasicHttpParams(); 
                HttpConnectionParams.setConnectionTimeout(httpParameters, 20000);
                HttpConnectionParams.setSoTimeout(httpParameters, 20000);
                DefaultHttpClient client = new DefaultHttpClient(httpParameters);

                HttpPost request = new HttpPost(SERVER_URL);
                request.setEntity(entity);

                HttpResponse response = null;
                response = client.execute(request);
                BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                StringBuffer result = new StringBuffer();
                String line = "";
                while ((line = rd.readLine()) != null) {
                    result.append(line);
                }
                String res = result.toString();
                if(res.toLowerCase().contains("done")
                        || res.toLowerCase().contains("ok")
                        || res.toLowerCase().contains("success"))
                    return true;
            }catch(Throwable ex){
                ex.printStackTrace();
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean result)
        {
            if(pDialog != null && pDialog.isShowing())
                pDialog.dismiss();
            //
            if(result)
                Toast.makeText(Esignature.this, "Signature Submitted Successfully", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(Esignature.this, "Failed to Submit Signature", Toast.LENGTH_LONG).show();

            if(result)
            {
                if (gestureTouch == false) {
                    setResult(0);
                    finish();
                } else {
                    setResult(1);
                    finish();
                }
            }
            super.onPostExecute(result);
        }

    }

}

1 个答案:

答案 0 :(得分:0)

当签名被发送到服务器并且服务器接受了它( onPostExecute 被调用为true)时,在本地保存已提供签名的订单。如您提供的代码中没有给出任何信息,如何建模订单,我只能猜测您可能需要添加一个额外的布尔属性,如 signatureProvided

打开订单明细活动时,请检查该订单是否已提供签名,如果是这种情况,则通过调用 button禁用该按钮.setEnabled(false)