Example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE

List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE

Introduction

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

Prototype

String ACTION_IMAGE_CAPTURE

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

Click Source Link

Document

Standard Intent action that can be sent to have the camera application capture an image and return it.

Usage

From source file:com.sxt.superqq.activity.ChatActivity.java

/**
 * ???/*from w  w  w.  j a v  a  2s  .  com*/
 */
private void setTakePictureClickListener() {
    findViewById(R.id.btn_picture).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!CommonUtils.isExitsSdcard()) {
                String st = getResources().getString(R.string.sd_card_does_not_exist);
                Toast.makeText(getApplicationContext(), st, 0).show();
                return;
            }

            cameraFile = new File(PathUtil.getInstance().getImagePath(),
                    SuperQQApplication.getInstance().getUserName() + 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:kr.wdream.ui.WallpapersActivity.java

@Override
public View createView(Context context) {
    Log.d(LOG_TAG, "createView");

    actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(//ww  w . j a  va  2 s .  c  om
            LocaleController.getString("ChatBackground", kr.wdream.storyshop.R.string.ChatBackground));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                boolean done;
                TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
                if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
                    int width = AndroidUtilities.displaySize.x;
                    int height = AndroidUtilities.displaySize.y;
                    if (width > height) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes,
                            Math.min(width, height));
                    String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
                    File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE),
                            fileName);
                    File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                    try {
                        done = AndroidUtilities.copyFile(f, toFile);
                    } catch (Exception e) {
                        done = false;
                        FileLog.e("tmessages", e);
                    }
                } else {
                    if (selectedBackground == -1) {
                        File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg");
                        File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                        done = fromFile.renameTo(toFile);
                    } else {
                        done = true;
                    }
                }

                if (done) {
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putInt("selectedBackground", selectedBackground);
                    editor.putInt("selectedColor", selectedColor);
                    editor.commit();
                    ApplicationLoader.reloadWallpaper();
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, kr.wdream.storyshop.R.drawable.ic_done,
            AndroidUtilities.dp(56));

    FrameLayout frameLayout = new FrameLayout(context);
    fragmentView = frameLayout;

    backgroundImage = new ImageView(context);
    backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    frameLayout.addView(backgroundImage,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    backgroundImage.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52));

    progressViewBackground = new View(context);
    progressViewBackground.setBackgroundResource(kr.wdream.storyshop.R.drawable.system_loader);
    progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    ProgressBar progressBar = new ProgressBar(context);
    try {
        progressBar.setIndeterminateDrawable(
                context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.loading_animation));
    } catch (Exception e) {
        //don't promt
    }
    progressBar.setIndeterminate(true);
    AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500);
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    RecyclerListView listView = new RecyclerListView(context);
    listView.setClipToPadding(false);
    listView.setTag(8);
    listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    listView.setLayoutManager(layoutManager);
    listView.setDisallowInterceptTouchEvents(true);
    listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM));
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position == 0) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items = new CharSequence[] {
                        LocaleController.getString("FromCamera", kr.wdream.storyshop.R.string.FromCamera),
                        LocaleController.getString("FromGalley", kr.wdream.storyshop.R.string.FromGalley),
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel) };

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        try {
                            if (i == 0) {
                                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                File image = AndroidUtilities.generatePicturePath();
                                if (image != null) {
                                    if (Build.VERSION.SDK_INT >= 24) {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                FileProvider.getUriForFile(getParentActivity(),
                                                        BuildConfig.APPLICATION_ID + ".provider", image));
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                    } else {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                Uri.fromFile(image));
                                    }
                                    currentPicturePath = image.getAbsolutePath();
                                }
                                startActivityForResult(takePictureIntent, 10);
                            } else if (i == 1) {
                                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, 11);
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                    }
                });
                showDialog(builder.create());
            } else {
                if (position - 1 < 0 || position - 1 >= wallPapers.size()) {
                    return;
                }
                TLRPC.WallPaper wallPaper = wallPapers.get(position - 1);
                selectedBackground = wallPaper.id;
                listAdapter.notifyDataSetChanged();
                processSelectedBackground();
            }
        }
    });

    processSelectedBackground();

    return fragmentView;
}

From source file:com.collecdoo.fragment.main.RegisterDriverPhotoFragment.java

@Override
public void onActivityResult(final int requestCode, int resultCode, Intent data) {

    if (resultCode == AppCompatActivity.RESULT_OK) {

        if (resultCode == Activity.RESULT_OK) {
            final boolean isCamera;
            if (data == null) {
                isCamera = true;/*from w  ww  . j  a  v  a2s  .  c  o m*/
            } else {
                final String action = data.getAction();
                if (action == null) {
                    isCamera = false;
                } else {
                    isCamera = action.equals(MediaStore.ACTION_IMAGE_CAPTURE);
                }
            }
            Uri selectedImageUri;
            if (isCamera) {
                selectedImageUri = cameraOutputFileUri;

            } else {
                selectedImageUri = data == null ? null : data.getData();

            }
            try {
                Bitmap bitmap = decodeUri(selectedImageUri);

                String strPhoto = null;
                try {
                    strPhoto = URLEncoder.encode(encodeBitmapBase64(bitmap), "utf-8");
                    Log.d(Constant.DEBUG_TAG, strPhoto);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                switch (requestCode) {
                case 1:
                    txtPicture.setText("uploaded");
                    strAvatar = strPhoto;
                    break;
                case 2:
                    txtDriveLicense.setText("uploaded");
                    //strDriverLicense=strPhoto;
                    break;
                case 3:
                    txtBusinessRegis.setText("uploaded");
                    //strBusiness=strPhoto;
                    break;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}

From source file:de.azapps.mirakel.main_activity.task_fragment.TaskFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    this.cabState = null;
    this.markedFiles = new LongSparseArray<>();
    this.markedSubtasks = new LongSparseArray<>();
    this.main = (MainActivity) getActivity();
    View view;// w w  w  .j a  v a2  s . c o m
    this.updateThread = new Runnable() {
        @Override
        public void run() {
            TaskFragment.this.detailView.update(TaskFragment.this.task);
        }
    };
    try {
        view = inflater.inflate(R.layout.task_fragment, container, false);
    } catch (final Exception e) {
        Log.w(TaskFragment.TAG, "Failed do inflate layout", e);
        return null;
    }
    this.detailView = (TaskDetailView) view.findViewById(R.id.task_fragment_view);
    this.detailView.setOnTaskChangedListner(new OnTaskChangedListner() {
        @Override
        public void onTaskChanged(final Task newTask) {
            if (TaskFragment.this.main.getTasksFragment() != null
                    && TaskFragment.this.main.getListFragment() != null) {
                TaskFragment.this.main.getTasksFragment().updateList();
                TaskFragment.this.main.getListFragment().update();
            }
        }
    });
    this.detailView.setOnSubtaskClick(new OnTaskClickListener() {
        @Override
        public void onTaskClick(final Task t) {
            TaskFragment.this.main.setCurrentTask(t);
        }
    });
    this.detailView.setFragmentManager(new NeedFragmentManager() {
        @Override
        public FragmentManager getFragmentManager() {
            return TaskFragment.this.main.getSupportFragmentManager();
        }
    });
    if (MirakelCommonPreferences.useBtnCamera()
            && Helpers.isIntentAvailable(this.main, MediaStore.ACTION_IMAGE_CAPTURE)) {
        this.detailView.setAudioButtonClick(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                TaskDialogHelpers.handleAudioRecord(getActivity(), TaskFragment.this.task,
                        new ExecInterfaceWithTask() {
                            @Override
                            public void exec(final Task t) {
                                update(t);
                            }
                        });
            }
        });
        this.detailView.setCameraButtonClick(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                try {
                    final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    final Uri fileUri = FileUtils.getOutputMediaFileUri(FileUtils.MEDIA_TYPE_IMAGE);
                    if (fileUri == null) {
                        return;
                    }
                    TaskFragment.this.main.setFileUri(fileUri);
                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
                    getActivity().startActivityForResult(cameraIntent, MainActivity.RESULT_ADD_PICTURE);
                } catch (final ActivityNotFoundException a) {
                    ErrorReporter.report(ErrorType.PHOTO_NO_CAMERA);
                } catch (final IOException e) {
                    if (e.getMessage().equals(FileUtils.ERROR_NO_MEDIA_DIR)) {
                        ErrorReporter.report(ErrorType.PHOTO_NO_MEDIA_DIRECTORY);
                    }
                }
            }
        });
    }
    if (this.task != null) {
        update(this.task);
    }
    this.detailView.setOnSubtaskMarked(new OnTaskMarkedListener() {
        @Override
        public void markTask(final View v, final Task t, final boolean marked) {
            if (t == null || TaskFragment.this.cabState != null
                    && TaskFragment.this.cabState != ActionbarState.SUBTASK) {
                return;
            }
            if (marked) {
                TaskFragment.this.cabState = ActionbarState.SUBTASK;
                if (mActionMode == null) {
                    main.startActionMode(mActionModeCallback);
                }
                v.setBackgroundColor(Helpers.getHighlightedColor(getActivity()));
                TaskFragment.this.markedSubtasks.put(t.getId(), t);
            } else {
                Log.d(TaskFragment.TAG, "not marked");
                v.setBackgroundColor(getActivity().getResources().getColor(android.R.color.transparent));
                TaskFragment.this.markedSubtasks.remove(t.getId());
                if (TaskFragment.this.markedSubtasks.size() == 0 && mActionMode != null) {
                    mActionMode.finish();
                }
            }
            if (TaskFragment.this.mMenu != null) {
                final MenuItem item = TaskFragment.this.mMenu.findItem(R.id.edit_task);
                if (mActionMode != null && item != null) {
                    item.setVisible(TaskFragment.this.markedSubtasks.size() == 1);
                }
            }
        }
    });
    this.detailView.setOnFileMarked(new OnFileMarkedListener() {
        @Override
        public void markFile(final View v, final FileMirakel e, final boolean marked) {
            if (e == null || TaskFragment.this.cabState != null
                    && TaskFragment.this.cabState != ActionbarState.FILE) {
                return;
            }
            if (marked) {
                TaskFragment.this.cabState = ActionbarState.FILE;
                if (mActionMode == null) {
                    main.startActionMode(mActionModeCallback);
                }
                v.setBackgroundColor(Helpers.getHighlightedColor(getActivity()));
                TaskFragment.this.markedFiles.put(e.getId(), e);
            } else {
                v.setBackgroundColor(getActivity().getResources().getColor(android.R.color.transparent));
                TaskFragment.this.markedFiles.remove(e.getId());
                if (TaskFragment.this.markedFiles.size() == 0 && mActionMode != null) {
                    mActionMode.finish();
                }
            }
        }
    });
    this.detailView.setOnFileClicked(new OnFileClickListener() {
        @Override
        public void clickOnFile(final FileMirakel file) {
            final Context context = getActivity();
            String[] items;
            if (FileUtils.isAudio(file.getFileUri())) {
                items = context.getResources().getStringArray(R.array.audio_playback_options);
            } else {
                TaskDialogHelpers.openFile(context, file);
                return;
            }
            new AlertDialog.Builder(context).setTitle(R.string.audio_playback_select_title)
                    .setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int which) {
                            switch (which) {
                            case 0: // Open
                                TaskDialogHelpers.openFile(context, file);
                                break;
                            default: // playback
                                TaskDialogHelpers.playbackFile(getActivity(), file, which == 1);
                                break;
                            }
                        }
                    }).show();
            return;
        }
    });
    this.detailView.update(this.main.getCurrentTask());
    return view;
}

From source file:de.wikilab.android.friendica01.activity.HomeActivity.java

void navigate(String arg1) {
    currentMMItem = arg1;//  w w w. java  2s .  c om

    if (arg1.equals(getResources().getString(R.string.mm_timeline))) {
        navigatePostList(getResources().getString(R.string.mm_timeline));
    }

    if (arg1.equals(getResources().getString(R.string.mm_notifications))) {
        navigatePostList(getResources().getString(R.string.mm_notifications));
    }

    if (arg1.equals(getResources().getString(R.string.mm_mywall))) {
        navigatePostList(getResources().getString(R.string.mm_mywall));
    }

    if (arg1.equals(getResources().getString(R.string.mm_updatemystatus))) {
        navigateStatusUpdate();
    }

    if (arg1.equals(getResources().getString(R.string.mm_friends))) {
        navigateFriendList();
    }

    if (arg1.equals(getResources().getString(R.string.mm_myphotoalbums))) {
        navigatePhotoGallery(getResources().getString(R.string.mm_myphotoalbums));
    }

    if (arg1.equals(getResources().getString(R.string.mm_takephoto))) {
        Intent in = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        takePhotoTarget = Max.getTempFile();
        in.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(takePhotoTarget));
        startActivityForResult(in, RQ_TAKE_PHOTO);
    }
    if (arg1.equals(getResources().getString(R.string.mm_selectphoto))) {
        Intent in = new Intent(Intent.ACTION_PICK);
        in.setType("image/*");
        startActivityForResult(in, RQ_SELECT_PHOTO);
    }
    if (arg1.equals(getResources().getString(R.string.mm_directmessages))) {
        //Intent in = new Intent(HomeActivity.this, MessagesActivity.class);
        //startActivity(in);
        navigateMessages("msg:all");
    }

    if (arg1.equals(getResources().getString(R.string.mm_preferences))) {
        navigatePreferences();
    }

    if (arg1.equals(getResources().getString(R.string.mm_logout))) {
        SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
                .edit();
        //prefs.putString("login_server", null); //keep server and user ...
        prefs.putString("login_user", null);
        prefs.putString("login_password", null); //...only remove password
        prefs.commit();

        finish();
    }

}

From source file:info.shibafu528.gallerymultipicker.MultiPickerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    int id = item.getItemId();
    if (id == android.R.id.home) {
        if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
            getSupportFragmentManager().popBackStack();
        } else {/*from www .  j  av a 2s. c o  m*/
            setResult(RESULT_CANCELED);
            finish();
        }
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_decide) {
        accept(getSelectedUris());
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_gallery) {
        Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_PICK
                : Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(intent, REQUEST_GALLERY);
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_take_a_photo) {
        boolean existExternal = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
        if (!existExternal) {
            Toast.makeText(this, R.string.info_shibafu528_gallerymultipicker_storage_error, Toast.LENGTH_SHORT)
                    .show();
            return true;
        } else {
            File extDestDir = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
                    mCameraDestDir != null ? mCameraDestDir : "Camera");
            if (!extDestDir.exists()) {
                extDestDir.mkdirs();
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
            String fileName = sdf.format(new Date(System.currentTimeMillis()));
            File destFile = new File(extDestDir.getPath(), fileName + ".jpg");
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            values.put(MediaStore.Images.Media.DATA, destFile.getPath());
            mCameraTemp = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraTemp);
            startActivityForResult(intent, REQUEST_CAMERA);
        }
    }
    return true;
}

From source file:com.android.camera.v2.uimanager.SettingManager.java

private void initializeSettings() {
    if (mSettingLayout == null) {
        mSettingLayout = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.setting_container_v2,
                mSettingViewLayer, false);
        mTabHost = (TabHost) mSettingLayout.findViewById(R.id.tab_title);
        mTabHost.setup();/*from   w  ww.  j av a2s  . c  o  m*/
        String action = mIntent.getAction();
        LogHelper.i(TAG, "intent.action:" + action);
        List<Holder> list = new ArrayList<Holder>();
        // default setting
        int commonKeys[] = SettingKeys.SETTING_GROUP_COMMON_FOR_TAB;
        int cameraKeys[] = SettingKeys.SETTING_GROUP_CAMERA_FOR_TAB;
        int videoKeys[] = SettingKeys.SETTING_GROUP_VIDEO_FOR_TAB;

        if (FeatureSwitcher.isSubSettingEnabled()) {
            // For tablet
            commonKeys = SettingKeys.SETTING_GROUP_MAIN_COMMON_FOR_TAB;
        } else if (FeatureSwitcher.isLomoEffectEnabled()) {
            commonKeys = SettingKeys.SETTING_GROUP_COMMON_FOR_LOMOEFFECT;
        }
        // image capture setting, compared to default setting,
        // common settings and video setting may be different.
        if (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)) {
            videoKeys = null;
        }
        // image capture setting, compared to default setting,
        // common settings and video setting
        // may be different.
        if (MediaStore.ACTION_VIDEO_CAPTURE.equals(action)) {
            cameraKeys = null;
        }

        if (commonKeys != null) {
            list.add(new Holder(TAB_INDICATOR_KEY_COMMON, R.drawable.ic_tab_common_setting, commonKeys));
        }
        if (cameraKeys != null) {
            list.add(new Holder(TAB_INDICATOR_KEY_CAMERA, R.drawable.ic_tab_camera_setting, cameraKeys));
        }
        if (videoKeys != null) {
            list.add(new Holder(TAB_INDICATOR_KEY_VIDEO, R.drawable.ic_tab_video_setting, videoKeys));
        }

        int size = list.size();
        List<SettingListLayout> pageViews = new ArrayList<SettingListLayout>();
        for (int i = 0; i < size; i++) {
            Holder holder = list.get(i);
            // new page view
            SettingListLayout pageView = (SettingListLayout) mActivity.getLayoutInflater()
                    .inflate(R.layout.setting_list_layout_v2, mSettingViewLayer, false);
            ArrayList<ListPreference> listItems = new ArrayList<ListPreference>();
            pageView.setRootView(mSettingViewLayer);
            pageView.initialize(getListPreferences(holder.mSettingKeys, i == 0));
            pageView.setSettingChangedListener(SettingManager.this);
            pageViews.add(pageView);
            // new indicator view
            ImageView indicatorView = new ImageView(mActivity);
            if (indicatorView != null) {
                indicatorView.setBackgroundResource(R.drawable.bg_tab_title);
                indicatorView.setImageResource(holder.mIndicatorIconRes);
                indicatorView.setScaleType(ScaleType.CENTER);
            }
            mTabHost.addTab(mTabHost.newTabSpec(holder.mIndicatorKey).setIndicator(indicatorView)
                    .setContent(android.R.id.tabcontent));
        }

        mAdapter = new MyPagerAdapter(pageViews);
        mPager = (ViewPager) mSettingLayout.findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);
        mPager.setOnPageChangeListener(mAdapter);
        mTabHost.setOnTabChangedListener(this);
    }
    int orientation = (Integer) mSettingViewLayer.getTag();
    CameraUtil.setOrientation(mSettingLayout, orientation, false);
}

From source file:im.vector.activity.RoomActivity.java

/**
 * Launch the camera/*from   w w w. jav  a  2s  .  c  o m*/
 */
private void launchCamera() {
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // the following is a fix for buggy 2.x devices
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, CAMERA_VALUE_TITLE + formatter.format(date));
    // The Galaxy S not only requires the name of the file to output the image to, but will also not
    // set the mime type of the picture it just took (!!!). We assume that the Galaxy S takes image/jpegs
    // so the attachment uploader doesn't freak out about there being no mimetype in the content database.
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    Uri dummyUri = null;
    try {
        dummyUri = RoomActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                values);
    } catch (UnsupportedOperationException uoe) {
        Log.e(LOG_TAG,
                "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI - no SD card? Attempting to insert into device storage.");
        try {
            dummyUri = RoomActivity.this.getContentResolver()
                    .insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
        } catch (Exception e) {
            Log.e(LOG_TAG, "Unable to insert camera URI into internal storage. Giving up. " + e);
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI. " + e);
    }
    if (dummyUri != null) {
        captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, dummyUri);
    }
    // Store the dummy URI which will be set to a placeholder location. When all is lost on samsung devices,
    // this will point to the data we're looking for.
    // Because Activities tend to use a single MediaProvider for all their intents, this field will only be the
    // *latest* TAKE_PICTURE Uri. This is deemed acceptable as the normal flow is to create the intent then immediately
    // fire it, meaning onActivityResult/getUri will be the next thing called, not another createIntentFor.
    RoomActivity.this.mLatestTakePictureCameraUri = dummyUri == null ? null : dummyUri.toString();

    startActivityForResult(captureIntent, TAKE_IMAGE);
}

From source file:geert.stef.sm.beheerautokm.Overview.java

public void addNewImage(View view) {
    if (view.getId() == R.id.btnAddNewImage) {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

            File photoFile = null;
            try {
                photoFile = createImageFile(selectedCar.getCar());
            } catch (IOException ex) {
                // Error occurred while creating the File

            }//w  w w.  j a v  a 2s .c  o m
            // Continue only if the File was successfully created
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                startActivityForResult(takePictureIntent, REQUEST_CODE_CAPTURE);
            }
        }
    }
}

From source file:com.awrtechnologies.carbudgetsales.MainActivity.java

public void imageOpen(Fragment f, final int REQUEST_CAMERA, final int SELECT_FILE) {

    GeneralHelper.getInstance(MainActivity.this).setTempFragment(f);
    final CharSequence[] items = { "Take Photo", "Choose from Library", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Add Photo!");
    builder.setItems(items, new DialogInterface.OnClickListener() {

        @Override/* w  ww  .  j ava 2  s.  co m*/
        public void onClick(DialogInterface dialog, int item) {
            if (items[item].equals("Take Photo")) {

                java.io.File imageFile = new File(
                        (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/."
                                + Constants.APPNAME + "/" + System.currentTimeMillis() + ".jpeg"));

                PreferencesManager.setPreferenceByKey(MainActivity.this, "IMAGEWWC",
                        imageFile.getAbsolutePath());
                //
                imageFilePath = imageFile;
                imageFileUri = Uri.fromFile(imageFile);
                Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
                startActivityForResult(i, REQUEST_CAMERA);

            } else if (items[item].equals("Choose from Library")) {
                if (Build.VERSION.SDK_INT < 19) {
                    Intent intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
                } else {
                    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
                }

            } else if (items[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}