Example usage for android.content Intent ACTION_PICK

List of usage examples for android.content Intent ACTION_PICK

Introduction

In this page you can find the example usage for android.content Intent ACTION_PICK.

Prototype

String ACTION_PICK

To view the source code for android.content Intent ACTION_PICK.

Click Source Link

Document

Activity Action: Pick an item from the data, returning what was selected.

Usage

From source file:com.annanovas.bestprice.DashBoardEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dash_board_edit);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w  ww. j  a v  a2s.  c o  m
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    //        chosenBrandList.add(new ArrayList<String>());
    //        chosenBrandList.add(new ArrayList<String>());
    //        chosenBrandList.add(new ArrayList<String>());

    etAddress = (EditText) findViewById(R.id.et_address);
    etEmail = (EditText) findViewById(R.id.et_email);
    etShopName = (EditText) findViewById(R.id.et_shop_name);
    etDrivingLicense = (EditText) findViewById(R.id.et_driving_licence);
    etNid = (EditText) findViewById(R.id.et_nid);
    etExperience = (EditText) findViewById(R.id.et_experience);
    etFirstName = (EditText) findViewById(R.id.et_first_name);
    etMiddleName = (EditText) findViewById(R.id.et_middle_name);
    etLastName = (EditText) findViewById(R.id.et_last_name);
    etPhoneNumber = (EditText) findViewById(R.id.et_phone);
    tvAddress = (TextView) findViewById(R.id.tv_address);
    tvArea = (TextView) findViewById(R.id.tv_area);
    tvDealerShip = (LinearLayout) findViewById(R.id.tv_dealership);
    tvDealerShipWith = (TextView) findViewById(R.id.tv_dealership_content);
    tvSelectedProduct = (TextView) findViewById(R.id.tv_select_product_content);
    tvProduct = (LinearLayout) findViewById(R.id.tv_select_product);
    buttonSubmit = (Button) findViewById(R.id.button_submit);
    areaLayout = (LinearLayout) findViewById(R.id.layout_area);
    brandLayout = (LinearLayout) findViewById(R.id.layout_brand);
    productLayout = (LinearLayout) findViewById(R.id.layout_product);
    layoutCamera = (LinearLayout) findViewById(R.id.layout_camera);
    layoutGallery = (LinearLayout) findViewById(R.id.layout_gallery);
    userImage = (ImageView) findViewById(R.id.iv_user_image);
    areaRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_area);
    brandRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_brand);
    productRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_product);
    etProductSearch = (EditText) findViewById(R.id.et_product_name);
    etBrandSearch = (EditText) findViewById(R.id.et_brand_name);
    etAreaSearch = (EditText) findViewById(R.id.et_area_name);
    layoutSearchArea = (LinearLayout) findViewById(R.id.layout_search_area);
    layoutSearchProduct = (LinearLayout) findViewById(R.id.layout_search_product);
    layoutSearchBrand = (LinearLayout) findViewById(R.id.layout_search_brand);
    tvSelectedBrand = (TextView) findViewById(R.id.tv_selected_brand);
    tvSelectedArea = (TextView) findViewById(R.id.tv_setect_area);
    ivArrow1 = (ImageView) findViewById(R.id.iv_arrow1);
    ivArrow2 = (ImageView) findViewById(R.id.iv_arrow2);
    ivArrow3 = (ImageView) findViewById(R.id.iv_arrow3);
    ivArrow4 = (ImageView) findViewById(R.id.iv_arrow4);

    myDB = MyDatabaseManager.getInstance(getApplicationContext());
    sharedPreferences = getSharedPreferences(AppGlobal.MY_PREFS_NAME, MODE_PRIVATE);

    userType = sharedPreferences.getInt("user_type", 1);

    int imageDimen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimension(R.dimen.size_150dp), getResources().getDisplayMetrics());

    myDB.open();
    Cursor cursor = myDB.getUserInfo(userType, sharedPreferences.getString("user_phone_number", ""));
    if (userType == AppGlobal.CAR_OWNER) {
        userImage.setImageResource(R.drawable.ic_car_owner);
        tvAddress.setVisibility(View.VISIBLE);
        etAddress.setVisibility(View.VISIBLE);
        tvArea.setVisibility(View.VISIBLE);
        areaLayout.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));

                if (cursor.getString(cursor.getColumnIndex("address")) != null
                        && !cursor.getString(cursor.getColumnIndex("address")).equals("null")) {
                    etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                }

                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                areaId = cursor.getInt(cursor.getColumnIndex("area_id"));
                if (areaId != 0) {
                    tvSelectedArea.setText(myDB.getAreaName(areaId));
                } else {
                    tvSelectedArea.setText(getResources().getString(R.string.select_area));
                }

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();

        generateAreaRecyclerView();

    } else if (userType == AppGlobal.SUPPLIER) {
        tvAddress.setVisibility(View.VISIBLE);
        etAddress.setVisibility(View.VISIBLE);
        tvDealerShip.setVisibility(View.VISIBLE);
        tvProduct.setVisibility(View.VISIBLE);
        tvArea.setVisibility(View.VISIBLE);
        brandLayout.setVisibility(View.VISIBLE);
        productLayout.setVisibility(View.VISIBLE);
        areaLayout.setVisibility(View.VISIBLE);
        etShopName.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                areaId = cursor.getInt(cursor.getColumnIndex("area_id"));
                if (areaId != 0) {
                    tvSelectedArea.setText(myDB.getAreaName(areaId));
                } else {
                    tvSelectedArea.setText(getResources().getString(R.string.select_area));
                }
                selectedProductIdList = myDB.getSelectedProductList(cursor.getInt(cursor.getColumnIndex("id")));
                chosenBrandIdList = myDB.getSelectedBrandList(cursor.getInt(cursor.getColumnIndex("id")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_supplier);
                }
            }
        }
        cursor.close();

        generateAreaRecyclerView();
        generateProductRecyclerView();

    } else if (userType == AppGlobal.DRIVER) {
        etDrivingLicense.setVisibility(View.VISIBLE);
        etNid.setVisibility(View.VISIBLE);
        etExperience.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etDrivingLicense.setText(cursor.getString(cursor.getColumnIndex("drivinglicence")));
                etNid.setText(cursor.getString(cursor.getColumnIndex("nid")));
                etExperience.setText(cursor.getString(cursor.getColumnIndex("yearofexperience")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();

    } else if (userType == AppGlobal.SHOP_WORKER) {
        etShopName.setVisibility(View.VISIBLE);
        etNid.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                etNid.setText(cursor.getString(cursor.getColumnIndex("nid")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();
    }
    myDB.close();

    areaLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (layoutSearchArea.getVisibility() == View.GONE) {
                layoutSearchArea.setVisibility(View.VISIBLE);
                areaRecyclerView.setVisibility(View.VISIBLE);
                ivArrow2.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchArea.setVisibility(View.GONE);
                areaRecyclerView.setVisibility(View.GONE);
                ivArrow2.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    brandLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (selectedProductIdList.size() == 0) {
                Toast.makeText(getApplicationContext(), R.string.add_product, Toast.LENGTH_SHORT).show();
                return;
            }
            if (layoutSearchBrand.getVisibility() == View.GONE) {
                layoutSearchBrand.setVisibility(View.VISIBLE);
                brandRecyclerView.setVisibility(View.VISIBLE);
                ivArrow3.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchBrand.setVisibility(View.GONE);
                brandRecyclerView.setVisibility(View.GONE);
                ivArrow3.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    productLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (layoutSearchProduct.getVisibility() == View.GONE) {
                layoutSearchProduct.setVisibility(View.VISIBLE);
                productRecyclerView.setVisibility(View.VISIBLE);
                ivArrow1.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchProduct.setVisibility(View.GONE);
                productRecyclerView.setVisibility(View.GONE);
                ivArrow1.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    layoutCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File file = createImageFile();
                imageUri = String.valueOf(file);
                // showLog(imageUri);
                Uri photoURI = FileProvider.getUriForFile(getApplicationContext(),
                        BuildConfig.APPLICATION_ID + ".provider", file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(intent, REQUEST_CAMERA);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    layoutGallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            intent.setType("image/*");
            startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
        }
    });

    buttonSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            progressDialog = new ProgressDialog(DashBoardEditActivity.this);
            progressDialog.setMessage(getResources().getString(R.string.please_wait));
            progressDialog.setCancelable(false);
            progressDialog.show();
            UpdateUserInfo updateUserInfo = new UpdateUserInfo(getApplicationContext());
            updateUserInfo.signUpListener = DashBoardEditActivity.this;
            //viewEnable(false);

            if (userType == AppGlobal.CAR_OWNER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }
                if (etAddress.getText().length() == 0) {
                    etAddress.setError(getResources().getString(R.string.enter_address));
                    hasError = true;
                }
                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("district_id", "1");
                params.put("area_id", String.valueOf(areaId));
                params.put("address", etAddress.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateCarOwnerInfo");
            } else if (userType == AppGlobal.SUPPLIER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }
                if (etShopName.getText().length() == 0) {
                    etShopName.setError(getResources().getString(R.string.enter_shop_name));
                    hasError = true;
                }
                if (etAddress.getText().length() == 0) {
                    etAddress.setError(getResources().getString(R.string.enter_address));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("district_id", "1");
                params.put("area_id", String.valueOf(areaId));
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                params.put("shopname", etShopName.getText().toString());
                params.put("address", etAddress.getText().toString());
                for (int i = 0; i < selectedProductIdList.size(); i++) {
                    params.put("products[" + i + "]", selectedProductIdList.get(i));
                }
                for (int i = 0; i < chosenBrandIdList.size(); i++) {
                    params.put("brands[" + i + "]", chosenBrandIdList.get(i));
                }
                updateUserInfo.parseData(params, "updateSupplierInfo");
            } else if (userType == AppGlobal.DRIVER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                boolean hasDrivingLicenseNoError = false;
                boolean hasNidNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }

                if (etDrivingLicense.getText().length() == 0) {
                    etDrivingLicense.setError(getResources().getString(R.string.enter_driving_licence));
                    hasError = true;
                    hasDrivingLicenseNoError = true;
                }

                if (!hasDrivingLicenseNoError && etDrivingLicense.getText().length() != 15) {
                    etDrivingLicense.setError(getResources().getString(R.string.enter_valid_driving_licence));
                    hasError = true;
                }
                if (etNid.getText().length() == 0) {
                    etNid.setError(getResources().getString(R.string.enter_nid_no));
                    hasError = true;
                    hasNidNoError = true;
                }
                if (!hasNidNoError && etNid.getText().length() != 17) {
                    etNid.setError(getResources().getString(R.string.enter_valid_nid));
                    hasError = true;
                }

                if (etExperience.getText().length() == 0) {
                    etExperience.setError(getResources().getString(R.string.enter_year_of_experience));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("drivinglicence", etDrivingLicense.getText().toString());
                params.put("nid", etNid.getText().toString());
                params.put("yearofexperience", etExperience.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateDriverInfo");
            } else if (userType == AppGlobal.SHOP_WORKER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }

                if (etNid.getText().length() == 0) {
                    etNid.setError(getResources().getString(R.string.enter_nid_no));
                    hasError = true;
                }

                if (etShopName.getText().length() == 0) {
                    etShopName.setError(getResources().getString(R.string.enter_shop_name));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("nid", etNid.getText().toString());
                params.put("shopname", etShopName.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateWorkerInfo");
            }
        }
    });
}

From source file:cn.zsmy.akm.doctor.profile.fragment.UploadPhotoFragment.java

/**
 * poppupwindow?position?button/*ww w  .ja va2 s .com*/
 *
 * @param0 ?
 * @param1 
 ****/
@Override
public void onItemClick(int position) {
    switch (position) {
    case 0:
        PHOTO_CREAME = CREAME;
        Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/"
                + String.valueOf(System.currentTimeMillis()) + ".jpg");
        tempUri = Uri.fromFile(file);
        openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
        startActivityForResult(openCameraIntent, PIC);
        break;
    case 1:
        PHOTO_CREAME = PHOTO;
        Intent i = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(i, PIC);
        break;
    default:
        break;
    }

    WHETHER_FROM_ACTIVITY_BACK = true;
}

From source file:nf.frex.android.FrexActivity.java

private void prepareColorsDialog(final Dialog dialog) {

    //Log.d(TAG, "prepareColorsDialog() entered");

    getColorSchemes();//from  w ww .  j  a  v a2  s .c o m

    //Log.d(TAG, "prepareColorsDialog: new bitmaps are being created");
    Bitmap[] colorSchemeIcons = new Bitmap[colorSchemes.getSize()];
    for (int i = 0; i < colorSchemeIcons.length; i++) {
        ColorScheme colorScheme = colorSchemes.getValue(i);
        colorSchemeIcons[i] = colorScheme.getGradientIcon();
    }

    int checkedIndex = Registries.colorSchemes.getIndex(view.getColorSchemeId());
    //Log.d(TAG, "prepareColorsDialog: checkedIndex = " + checkedIndex);
    final Spinner colorTableSpinner = (Spinner) dialog.findViewById(R.id.color_table_spinner);
    colorTableSpinner.setAdapter(new ImageArrayAdapter(this, 0, colorSchemeIcons));
    colorTableSpinner.setSelection(checkedIndex, false);
    colorTableSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) {
            view.setColorSchemeId(Registries.colorSchemes.getId(position));
            view.setColorScheme(Registries.colorSchemes.getValue(position));
            view.recomputeColors();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final SeekBar colorFactorSeekBar = (SeekBar) dialog.findViewById(R.id.color_gain_seek_bar);
    final double colorFactorMin = -3.0;
    final double colorFactorMax = 2.0;
    final SeekBarConfigurer colorFactorSeekBarConfigurer = SeekBarConfigurer.create(colorFactorSeekBar,
            colorFactorMin, colorFactorMax, true, view.getColorGain());
    colorFactorSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            view.setColorGain((float) colorFactorSeekBarConfigurer.getValue());
            view.recomputeColors();
        }
    });

    final SeekBar colorBiasSeekBar = (SeekBar) dialog.findViewById(R.id.color_offset_seek_bar);
    final double colorBiasMin = 0;
    final double colorBiasMax = 1024;
    final SeekBarConfigurer colorBiasSeekBarConfigurer = SeekBarConfigurer.create(colorBiasSeekBar,
            colorBiasMin, colorBiasMax, false, view.getColorOffset());
    colorBiasSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            view.setColorOffset((float) colorBiasSeekBarConfigurer.getValue());
            view.recomputeColors();
        }
    });

    final CheckBox colorRepeatCheckBox = (CheckBox) dialog.findViewById(R.id.color_repeat);
    colorRepeatCheckBox.setChecked(view.isColorRepeat());
    colorRepeatCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            view.setColorRepeat(isChecked);
            view.recomputeColors();
        }
    });

    Button randomButton = (Button) dialog.findViewById(R.id.random_button);
    randomButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            colorTableSpinner.setSelection((int) (Math.random() * colorSchemes.getSize()));
            colorFactorSeekBarConfigurer.setRandomValue();
            colorBiasSeekBarConfigurer.setRandomValue();
            view.recomputeColors();
        }
    });

    Button getPalFromImgButton = (Button) dialog.findViewById(R.id.get_pal_from_img_button);
    getPalFromImgButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            dialog.dismiss();
            startActivityForResult(photoPickerIntent, SELECT_PICTURE_REQUEST_CODE);
        }
    });

    //Log.d(TAG, "prepareColorsDialog() exited");
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

private void addImage() {

    // when clicking attack the user should at first select an application to
    // choose the image with and then choose an image.
    // this intent is for getting the image
    Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getIntent.setType("image/*");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        getIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

    // and this for getting the application to get the image with
    Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    pickIntent.setType("image/*");

    // and this finally is for opening the chooserIntent for opening the
    // getIntent for returning the image uri. Yep, thanks android
    Intent chooserIntent = Intent.createChooser(getIntent, getResources().getString(R.string.select_image));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { pickIntent });
    startActivityForResult(chooserIntent, ADD_PHOTO_CLICKED);
    // nope I don't want to be asked for a pwd when selected the image
    getActivity().getSharedPreferences(Constants.PREFERENCES, 0).edit().putBoolean(Constants.PWD_REQUEST, false)
            .apply();//from  ww  w  . j a  v  a  2  s  . c  om
}

From source file:org.andstatus.app.TimelineActivity.java

/**
 * Listener that checks for clicks on the main list view.
 * /*from ww  w .j av  a 2s. co m*/
 * @param adapterView
 * @param view
 * @param position
 * @param id
 */
@Override
public void onItemClick(AdapterView<?> adapterView, final View view, final int position, final long id) {
    if (id <= 0) {
        if (MyLog.isLoggable(this, MyLog.VERBOSE)) {
            MyLog.v(this, "onItemClick, position=" + position + "; id=" + id + "; view=" + view);
        }
        return;
    }

    new AsyncTask<Void, Void, Uri>() {

        @Override
        protected Uri doInBackground(Void... params) {
            long linkedUserId = getLinkedUserIdFromCursor(position);
            MyAccount ma = MyContextHolder.get().persistentAccounts().getAccountWhichMayBeLinkedToThisMessage(
                    id, linkedUserId, mListParametersNew.myAccountUserId);
            if (MyLog.isLoggable(this, MyLog.VERBOSE)) {
                MyLog.v(this, "onItemClick, position=" + position + "; id=" + id + "; view=" + view
                        + "; linkedUserId=" + linkedUserId + " account=" + ma.getAccountName());
            }
            return MyProvider.getTimelineMsgUri(ma.getUserId(), mListParametersNew.getTimelineType(), true, id);
        }

        @Override
        protected void onPostExecute(Uri uri) {
            String action = getIntent().getAction();
            if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
                if (MyLog.isLoggable(this, MyLog.DEBUG)) {
                    MyLog.d(this, "onItemClick, setData=" + uri);
                }
                setResult(RESULT_OK, new Intent().setData(uri));
            } else {
                if (MyLog.isLoggable(this, MyLog.DEBUG)) {
                    MyLog.d(this, "onItemClick, startActivity=" + uri);
                }
                startActivity(new Intent(Intent.ACTION_VIEW, uri));
            }
        }

    }.execute();
}

From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java

public void initPayeeControls() {
    this.viewHolder.txtSelectPayee.setOnClickListener(new View.OnClickListener() {
        @Override/*from  ww w  .j a v a2s  .c  o m*/
        public void onClick(View v) {
            Intent intent = new Intent(getContext(), PayeeActivity.class);
            intent.setAction(Intent.ACTION_PICK);
            getActivity().startActivityForResult(intent, RequestCodes.PAYEE);

            // the result is handled in onActivityResult
        }
    });

    viewHolder.removePayeeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setDirty(true);

            transactionEntity.setPayeeId(Constants.NOT_SET);
            payeeName = "";

            showPayeeName();
        }
    });
}

From source file:com.todoroo.astrid.actfm.EditPeopleControlSet.java

private boolean contactPickerAvailable() {
    Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    return activity.getPackageManager().queryIntentActivities(intent, 0).size() > 0;
}

From source file:com.android.music.AlbumBrowserFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
    intent.setClass(getActivity(), TrackBrowserActivity.class);
    intent.putExtra("album", Long.valueOf(id).toString());
    intent.putExtra("artist", mArtistId);
    startActivity(intent);//from   ww w.  j a  v  a 2s . c om

}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.AddDriver.java

private void galleryIntent() {
    if (btnClicked == UtilityBillsButton) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);//
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE_UtilityBills);
    } else if (btnClicked == BaseLetterButton) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);//
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE_BaseLetter);
    } else if (btnClicked == DriverLicenseButton) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);//
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE_DriverLicensebtn);
    } else if (btnClicked == TlcLicenseButton) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);//
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE_TlcLicensebtn);
    }/* w w  w. j  av a  2 s  .  c  o  m*/
}

From source file:net.gsantner.opoc.util.ShareUtil.java

/**
 * Request a picture from gallery/*  ww w  .j  a v  a  2 s  .  c o  m*/
 * Result will be available from {@link Activity#onActivityResult(int, int, Intent)}.
 * It will return the path to the image if locally stored. If retrieved from e.g. a cloud
 * service, the image will get copied to app-cache folder and it's path returned.
 */
public void requestGalleryPicture() {
    if (!(_context instanceof Activity)) {
        throw new RuntimeException("Error: ShareUtil.requestGalleryPicture needs an Activity Context.");
    }
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    ((Activity) _context).startActivityForResult(intent, REQUEST_PICK_PICTURE);
}