Example usage for android.provider MediaStore EXTRA_OUTPUT

List of usage examples for android.provider MediaStore EXTRA_OUTPUT

Introduction

In this page you can find the example usage for android.provider MediaStore EXTRA_OUTPUT.

Prototype

String EXTRA_OUTPUT

To view the source code for android.provider MediaStore EXTRA_OUTPUT.

Click Source Link

Document

The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video.

Usage

From source file:com.facebook.react.views.webview.ReactWebViewManager.java

@Override
protected WebView createViewInstance(final ThemedReactContext reactContext) {
    final ReactWebView webView = new ReactWebView(reactContext);

    /**// ww  w . jav  a2  s.  c om
     * cookie?
     * 5.0???cookie,5.0?false
     * 
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    }

    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            reactContext.getCurrentActivity().startActivity(intent);

            //                DownloadManager.Request request = new DownloadManager.Request(
            //                        Uri.parse(url));
            //
            //                request.setMimeType(mimetype);
            //                String cookies = CookieManager.getInstance().getCookie(url);
            //                request.addRequestHeader("cookie", cookies);
            //                request.addRequestHeader("User-Agent", userAgent);
            //                request.allowScanningByMediaScanner();
            ////                request.setTitle()
            //                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
            //                request.setDestinationInExternalPublicDir(
            //                        Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(
            //                                url, contentDisposition, mimetype));
            //                DownloadManager dm = (DownloadManager) reactContext.getCurrentActivity().getSystemService(DOWNLOAD_SERVICE);
            //                dm.enqueue(request);
            //                Toast.makeText(reactContext, "...", //To notify the Client that the file is being downloaded
            //                        Toast.LENGTH_LONG).show();

        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onConsoleMessage(ConsoleMessage message) {
            if (ReactBuildConfig.DEBUG) {
                return super.onConsoleMessage(message);
            }
            // Ignore console logs in non debug builds.
            return true;
        }

        @Override
        public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
        }

        private File createImageFile() throws IOException {
            // Create an image file name
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageFileName = "JPEG_" + timeStamp + "_";
            File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            File imageFile = new File(storageDir, /* directory */
                    imageFileName + ".jpg" /* filename */
            );
            return imageFile;
        }

        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                WebChromeClient.FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null) {
                mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent
                    .resolveActivity(reactContext.getCurrentActivity().getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    FLog.e(ReactConstants.TAG, "Unable to create Image File", ex);
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("*/*");

            Intent[] intentArray;
            if (takePictureIntent != null) {
                intentArray = new Intent[] { takePictureIntent };
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "?");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
            reactContext.getCurrentActivity().startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            // final Intent galleryIntent = new Intent(Intent.ACTION_PICK);
            // galleryIntent.setType("image/*");
            // final Intent chooserIntent = Intent.createChooser(galleryIntent, "Choose File");
            // reactContext.getCurrentActivity().startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }

        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {

            if (mVideoView != null) {
                callback.onCustomViewHidden();
                return;
            }

            // Store the view and it's callback for later, so we can dispose of them correctly
            mVideoView = view;
            mCustomViewCallback = callback;

            view.setBackgroundColor(Color.BLACK);
            getRootView().addView(view, FULLSCREEN_LAYOUT_PARAMS);
            webView.setVisibility(View.GONE);

            UiThreadUtil.runOnUiThread(new Runnable() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void run() {
                    // If the status bar is translucent hook into the window insets calculations
                    // and consume all the top insets so no padding will be added under the status bar.
                    View decorView = reactContext.getCurrentActivity().getWindow().getDecorView();
                    decorView.setOnApplyWindowInsetsListener(null);
                    ViewCompat.requestApplyInsets(decorView);
                }
            });

            reactContext.getCurrentActivity()
                    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        }

        @Override
        public void onHideCustomView() {
            if (mVideoView == null) {
                return;
            }

            mVideoView.setVisibility(View.GONE);
            getRootView().removeView(mVideoView);
            mVideoView = null;
            mCustomViewCallback.onCustomViewHidden();
            webView.setVisibility(View.VISIBLE);
            //                View decorView = reactContext.getCurrentActivity().getWindow().getDecorView();
            //                // Show Status Bar.
            //                int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
            //                decorView.setSystemUiVisibility(uiOptions);

            UiThreadUtil.runOnUiThread(new Runnable() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void run() {
                    // If the status bar is translucent hook into the window insets calculations
                    // and consume all the top insets so no padding will be added under the status bar.
                    View decorView = reactContext.getCurrentActivity().getWindow().getDecorView();
                    //                                decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                    //                                    @Override
                    //                                    public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                    //                                        WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                    //                                        return defaultInsets.replaceSystemWindowInsets(
                    //                                                defaultInsets.getSystemWindowInsetLeft(),
                    //                                                0,
                    //                                                defaultInsets.getSystemWindowInsetRight(),
                    //                                                defaultInsets.getSystemWindowInsetBottom());
                    //                                    }
                    //                                });
                    decorView.setOnApplyWindowInsetsListener(null);
                    ViewCompat.requestApplyInsets(decorView);
                }
            });

            reactContext.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        }

        private ViewGroup getRootView() {
            return ((ViewGroup) reactContext.getCurrentActivity().findViewById(android.R.id.content));
        }

    });

    reactContext.addLifecycleEventListener(webView);
    reactContext.addActivityEventListener(new ActivityEventListener() {
        @Override
        public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
            if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
                return;
            }
            Uri[] results = null;

            // Check that the response is a good one
            if (resultCode == Activity.RESULT_OK) {
                if (data == null) {
                    // If there is not data, then we may have taken a photo
                    if (mCameraPhotoPath != null) {
                        results = new Uri[] { Uri.parse(mCameraPhotoPath) };
                    }
                } else {
                    String dataString = data.getDataString();
                    if (dataString != null) {
                        results = new Uri[] { Uri.parse(dataString) };
                    }
                }
            }

            if (results == null) {
                mFilePathCallback.onReceiveValue(new Uri[] {});
            } else {
                mFilePathCallback.onReceiveValue(results);
            }
            mFilePathCallback = null;
            return;
        }

        @Override
        public void onNewIntent(Intent intent) {
        }
    });
    mWebViewConfig.configWebView(webView);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDefaultFontSize(16);
    webView.getSettings().setTextZoom(100);
    // Fixes broken full-screen modals/galleries due to body height being 0.
    webView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    return webView;
}

From source file:com.grass.caishi.cc.activity.AdAddActivity.java

/**
 * ?/*w w w  .j  a v a 2  s  .c o m*/
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        Toast.makeText(getApplicationContext(), "SD????", Toast.LENGTH_SHORT).show();
        return;
    }

    // cameraFile = new File(PathUtil.getInstance().getImagePath(),
    // DemoApplication.getInstance().getUserName()
    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            MyApplication.getInstance().getUser() + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}

From source file:com.example.innf.newchangtu.Map.view.activity.MainActivity.java

private void initFAB() {

    mFloatingActionsMenu = (FloatingActionsMenu) findViewById(R.id.floating_actions_menu);

    /**///w  w  w  .j a  v  a 2 s .  c  om
    mActionExchangeMap = (FloatingActionButton) findViewById(R.id.action_exchange_map);
    mActionExchangeMap.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mBaiduMap.getMapType() == BaiduMap.MAP_TYPE_NORMAL) {
                mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
                mActionExchangeMap.setTitle(getResources().getString(R.string.fab_exchange_map_normal));
            } else {
                mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
                mActionExchangeMap.setTitle(getResources().getString(R.string.fab_exchange_map_site));
            }
            mFloatingActionsMenu.toggle();
        }
    });

    /*?*/
    mActionExchangeModel = (FloatingActionButton) findViewById(R.id.action_exchange_model);
    mActionExchangeModel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mLocationMode == MyLocationConfiguration.LocationMode.NORMAL) {
                mLocationMode = MyLocationConfiguration.LocationMode.COMPASS;
                mActionExchangeModel.setTitle(getResources().getString(R.string.fab_exchange_model_common));
            } else {
                mLocationMode = MyLocationConfiguration.LocationMode.NORMAL;
                mActionExchangeModel.setTitle(getResources().getString(R.string.fab_exchange_model_compass));
            }
            mFloatingActionsMenu.toggle();
        }
    });

    /**/
    mActionFastBroadcast = (FloatingActionButton) findViewById(R.id.action_fast_broadcast);
    mActionFastBroadcast.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            fastSend();
            mFloatingActionsMenu.toggle();
        }
    });

    /*??*/
    mActionPhotoRecord = (FloatingActionButton) findViewById(R.id.action_fab_recognizes_license_plate);
    mActionPhotoRecord.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (null == mTrack) {
                Snackbar.make(view, "?", Snackbar.LENGTH_LONG).show();
            } else {
                if (isSdcardExisting()) {
                    Intent captureImageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTrackPhotoUri(mTrack));
                    startActivityForResult(captureImageIntent, REQUEST_TRACK_PHOTO);
                } else {
                    Snackbar.make(view, "?SD?", Snackbar.LENGTH_LONG).show();
                }
            }
            mFloatingActionsMenu.toggle();
        }
    });

    /*?????*/
    mActionFastLocal = (FloatingActionButton) findViewById(R.id.action_fast_local);
    mActionFastLocal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            /*??*/
            centerToMyLocation();
            if (null == mTrack) {
                mTrack = new Track();
                Position position = new Position();
                position.setPosition(getStatus());
                position.setMessage("");
                mPositionList.add(position);
                mTrack.setStartPosition(getStatus());
                mTrack.setPositionList(mPositionList);
                isPositionEmpty(mPositionList);
                updateUI();
            } else {
                addPosition();
            }
            mFloatingActionsMenu.toggle();
        }
    });
}

From source file:foam.littlej.android.app.ui.phone.AddReportActivity.java

/**
 * Create various dialog/* ww  w . j  a v  a2  s .com*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_MULTIPLE_CATEGORY: {
        if (showCategories() != null) {
            return new AlertDialog.Builder(this).setTitle(R.string.choose_categories)
                    .setMultiChoiceItems(showCategories(), setCheckedCategories(),
                            new DialogInterface.OnMultiChoiceClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton,
                                        boolean isChecked) {
                                    // see if categories have previously

                                    if (isChecked) {
                                        mVectorCategories.add(mCategoriesId.get(whichButton));

                                        mError = false;
                                    } else {
                                        mVectorCategories.remove(mCategoriesId.get(whichButton));
                                    }

                                    setSelectedCategories(mVectorCategories);
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            /* User clicked Yes so do some stuff */
                        }
                    }).create();
        }
    }

    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR),
                mCalendar.get(Calendar.MINUTE), false);

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                new DiscardTask(AddReportActivity.this).execute((String) null);
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete report
                deleteReport();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

/******************************************/
public void captureImage(View view) {
    try {//from  w ww  .  j av  a2  s.  c  o m
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            try {
                photoFile = createImageFile();
                //
                image_uri = Uri.fromFile(photoFile);
            } catch (IOException ex) {
                // Error occurred while creating the File
                Log.i(TAG, "Error");
            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, image_uri);
                takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
                        getResources().getConfiguration().orientation);
                //    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,uriSavedImage);
                startActivityForResult(takePictureIntent, CAPTURE_IMAGE);
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Error" + e.getMessage());
    }
}

From source file:com.example.zf_android.activity.MerchantEdit.java

private void show3Dialog(int type, final String uri) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MerchantEdit.this);
    final String[] items = getResources().getStringArray(R.array.apply_detail_view);

    MerchantEdit.this.type = type;
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override//from   w  ww.  j a  v a  2  s.  c o  m
        public void onClick(DialogInterface dialog, int which) {

            switch (which) {
            case 0: {

                AlertDialog.Builder build = new AlertDialog.Builder(MerchantEdit.this);
                LayoutInflater factory = LayoutInflater.from(MerchantEdit.this);
                final View textEntryView = factory.inflate(R.layout.show_view, null);
                build.setView(textEntryView);
                final ImageView view = (ImageView) textEntryView.findViewById(R.id.imag);
                //               ImageCacheUtil.IMAGE_CACHE.get(uri, view);
                ImageLoader.getInstance().displayImage(uri, view, options);
                build.create().show();
                break;
            }

            case 1: {

                Intent intent;
                if (Build.VERSION.SDK_INT < 19) {
                    intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("image/*");
                } else {
                    intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                }
                startActivityForResult(intent, REQUEST_UPLOAD_IMAGE);
                break;
            }
            case 2: {
                String state = Environment.getExternalStorageState();
                if (state.equals(Environment.MEDIA_MOUNTED)) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                    if (!outDir.exists()) {
                        outDir.mkdirs();
                    }
                    File outFile = new File(outDir, System.currentTimeMillis() + ".jpg");
                    photoPath = outFile.getAbsolutePath();
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile));
                    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                    startActivityForResult(intent, REQUEST_TAKE_PHOTO);
                } else {
                    CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_no_sdcard));
                }
                break;
            }
            }
        }
    });

    builder.show();
}

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);/*  w w w.j  a  va  2  s .  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:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

public static void takePicture(Context ctx, Uri mFileCaptureUri) {
    if (!isIntentAvailable(ctx, MediaStore.ACTION_IMAGE_CAPTURE)) {
        log.warn("Cannot take picture (Intent is not available)");
        return;/*from   www  .  j  ava 2 s  .c om*/
    }

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileCaptureUri);
    intent.putExtra("return-data", true);

    try {
        ((Activity) ctx).startActivityForResult(intent, AppUtils.ACTION_TAKE_PICTURE);
    } catch (ActivityNotFoundException e) {
        log.warn("Cannot take picture", e);
    }
}

From source file:com.almalence.opencam.ApplicationScreen.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    sEvPref = getResources().getString(R.string.Preference_EvCompensationValue);
    sSceneModePref = getResources().getString(R.string.Preference_SceneModeValue);
    sWBModePref = getResources().getString(R.string.Preference_WBModeValue);
    sColorTemperaturePref = getResources().getString(R.string.Preference_ColorTemperatureValue);
    sFrontFocusModePref = getResources().getString(R.string.Preference_FrontFocusModeValue);
    sFrontFocusModeVideoPref = getResources().getString(R.string.Preference_FrontFocusModeVideoValue);
    sRearFocusModePref = getResources().getString(R.string.Preference_RearFocusModeValue);
    sRearFocusModeVideoPref = getResources().getString(R.string.Preference_RearFocusModeVideoValue);
    sFrontColorEffectPref = getResources().getString(R.string.Preference_FrontColorEffectValue);
    sRearColorEffectPref = getResources().getString(R.string.Preference_RearColorEffectValue);
    sFlashModePref = getResources().getString(R.string.Preference_FlashModeValue);
    sISOPref = getResources().getString(R.string.Preference_ISOValue);
    sMeteringModePref = getResources().getString(R.string.Preference_MeteringModeValue);
    sExposureTimePref = getResources().getString(R.string.Preference_ExposureTimeValue);
    sExposureTimeModePref = getResources().getString(R.string.Preference_ExposureTimeModeValue);
    sRealExposureTimeOnPreviewPref = getResources()
            .getString(R.string.Preference_RealExposureTimeOnPreviewValue);
    sFocusDistancePref = getResources().getString(R.string.Preference_FocusDistanceValue);
    sFocusDistanceModePref = getResources().getString(R.string.Preference_FocusDistanceModeValue);
    sCameraModePref = getResources().getString(R.string.Preference_CameraModeValue);

    sUseFrontCameraPref = getResources().getString(R.string.Preference_UseFrontCameraValue);

    sImageSizeRearPref = getResources().getString(R.string.Preference_ImageSizeRearValue);
    sImageSizeFrontPref = getResources().getString(R.string.Preference_ImageSizeFrontValue);
    sImageSizeSonyRemotePref = getResources().getString(R.string.Preference_ImageSizeSonyRemoteValue);

    sImageSizeMultishotBackPref = getResources()
            .getString(R.string.Preference_ImageSizePrefSmartMultishotBackValue);
    sImageSizeMultishotFrontPref = getResources()
            .getString(R.string.Preference_ImageSizePrefSmartMultishotFrontValue);
    sImageSizeMultishotSonyRemotePref = getResources()
            .getString(R.string.Preference_ImageSizePrefSmartMultishotSonyRemoteValue);

    sImageSizePanoramaBackPref = getResources().getString(R.string.Preference_ImageSizePrefPanoramaBackValue);
    sImageSizePanoramaFrontPref = getResources().getString(R.string.Preference_ImageSizePrefPanoramaFrontValue);

    sImageSizeVideoBackPref = getResources().getString(R.string.Preference_ImageSizePrefVideoBackValue);
    sImageSizeVideoFrontPref = getResources().getString(R.string.Preference_ImageSizePrefVideoFrontValue);

    sCaptureRAWPref = getResources().getString(R.string.Preference_CaptureRAWValue);

    sJPEGQualityPref = getResources().getString(R.string.Preference_JPEGQualityCommonValue);

    sAntibandingPref = getResources().getString(R.string.Preference_AntibandingValue);

    sExportNamePref = getResources().getString(R.string.Preference_ExportNameValue);
    sExportNameSeparatorPref = getResources().getString(R.string.Preference_ExportNameSeparatorValue);
    sExportNamePrefixPref = getResources().getString(R.string.Preference_SavePathPrefixValue);
    sExportNamePostfixPref = getResources().getString(R.string.Preference_SavePathPostfixValue);
    sSavePathPref = getResources().getString(R.string.Preference_SavePathValue);
    sSaveToPref = getResources().getString(R.string.Preference_SaveToValue);
    sSortByDataPref = getResources().getString(R.string.Preference_SortByDataValue);
    sEnableExifOrientationTagPref = getResources().getString(R.string.Preference_EnableExifTagOrientationValue);
    sAdditionalRotationPref = getResources().getString(R.string.Preference_AdditionalRotationValue);
    sUseGeotaggingPref = getResources().getString(R.string.Preference_UseGeotaggingValue);

    sTimestampDate = getResources().getString(R.string.Preference_TimestampDateValue);
    sTimestampAbbreviation = getResources().getString(R.string.Preference_TimestampAbbreviationValue);
    sTimestampTime = getResources().getString(R.string.Preference_TimestampTimeValue);
    sTimestampGeo = getResources().getString(R.string.Preference_TimestampGeoValue);
    sTimestampSeparator = getResources().getString(R.string.Preference_TimestampSeparatorValue);
    sTimestampCustomText = getResources().getString(R.string.Preference_TimestampCustomTextValue);
    sTimestampColor = getResources().getString(R.string.Preference_TimestampColorValue);
    sTimestampFontSize = getResources().getString(R.string.Preference_TimestampFontSizeValue);

    sAELockPref = getResources().getString(R.string.Preference_AELockValue);
    sAWBLockPref = getResources().getString(R.string.Preference_AWBLockValue);

    sExpoPreviewModePref = getResources().getString(R.string.Preference_ExpoBracketingPreviewModePref);

    sDefaultModeName = getResources().getString(R.string.Preference_DefaultModeName);

    mainContext = this.getBaseContext();
    messageHandler = new Handler(this);
    instance = this;

    surfaceCreated = false;/*from  w  ww  . j  a va2 s . c o  m*/

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // ensure landscape orientation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    // set to fullscreen
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    // set some common view here
    //      setContentView(R.layout.opencamera_main_layout);

    createPluginManager();
    duringOnCreate();

    try {
        cameraController = CameraController.getInstance();
    } catch (VerifyError exp) {
        Log.e("ApplicationScreen", exp.getMessage());
    }
    CameraController.onCreate(ApplicationScreen.instance, ApplicationScreen.instance, pluginManager,
            ApplicationScreen.instance.messageHandler);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    keepScreenOn = prefs.getBoolean("keepScreenOn", false);

    // set preview, on click listener and surface buffers
    //      findViewById(R.id.SurfaceView02).setVisibility(View.GONE);
    //      preview = (SurfaceView) this.findViewById(R.id.SurfaceView01);
    //      preview.setOnClickListener(this);
    //      preview.setOnTouchListener(this);
    //      preview.setKeepScreenOn(true);
    //
    //      surfaceHolder = preview.getHolder();
    //      surfaceHolder.addCallback(this);

    orientListener = new OrientationEventListener(this) {
        @Override
        public void onOrientationChanged(int orientation) {
            // figure landscape or portrait
            if (ApplicationScreen.instance.landscapeIsNormal) {
                orientation += 90;
            }

            if ((orientation < 45) || (orientation > 315 && orientation < 405)
                    || ((orientation > 135) && (orientation < 225))) {
                if (ApplicationScreen.wantLandscapePhoto) {
                    ApplicationScreen.wantLandscapePhoto = false;
                }
            } else {
                if (!ApplicationScreen.wantLandscapePhoto) {
                    ApplicationScreen.wantLandscapePhoto = true;
                }
            }

            // orient properly for video
            if ((orientation > 135) && (orientation < 225))
                orientationMain = 270;
            else if ((orientation < 45) || (orientation > 315))
                orientationMain = 90;
            else if ((orientation < 325) && (orientation > 225))
                orientationMain = 0;
            else if ((orientation < 135) && (orientation > 45))
                orientationMain = 180;

            if (orientationMain != orientationMainPrevious) {
                orientationMainPrevious = orientationMain;
            }
        }
    };

    // prevent power drain
    screenTimer = new CountDownTimer(180000, 180000) {
        public void onTick(long millisUntilFinished) {
            // Not used
        }

        public void onFinish() {
            boolean isVideoRecording = PreferenceManager
                    .getDefaultSharedPreferences(ApplicationScreen.getMainContext())
                    .getBoolean("videorecording", false);
            if (isVideoRecording || keepScreenOn) {
                // restart timer
                screenTimer.start();
                isScreenTimerRunning = true;
                if (preview != null) {
                    preview.setKeepScreenOn(true);
                }
                return;
            }
            if (preview != null) {
                preview.setKeepScreenOn(keepScreenOn);
            }
            isScreenTimerRunning = false;
        }
    };
    screenTimer.start();
    isScreenTimerRunning = true;

    if (this.getIntent().getAction() != null) {
        if (this.getIntent().getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) {
            try {
                forceFilenameUri = this.getIntent().getExtras().getParcelable(MediaStore.EXTRA_OUTPUT);
                ApplicationScreen.setForceFilename(new File(((Uri) forceFilenameUri).getPath()));
                if (ApplicationScreen.getForceFilename().getAbsolutePath().equals("/scrapSpace")) {
                    ApplicationScreen.setForceFilename(
                            new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                                    + "/mms/scrapSpace/.temp.jpg"));
                    new File(ApplicationScreen.getForceFilename().getParent()).mkdirs();
                }
            } catch (Exception e) {
                ApplicationScreen.setForceFilename(null);
            }
        } else {
            ApplicationScreen.setForceFilename(null);
        }
    } else {
        ApplicationScreen.setForceFilename(null);
    }

    afterOnCreate();
}

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

/**
 * poppupwindow?position?button/*from w ww  . j a  v  a  2s .c  om*/
 *
 * @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;
}