Search in sources :

Example 1 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project RxMVP by Yumore.

the class ManageFragment method onClick.

@Override
public void onClick(View view) {
    RxPermissions permissions = new RxPermissions(getFragment());
    if (view.getId() == R.id.btn_package) {
        permissions.setLogging(true);
        permissions.request(Manifest.permission.READ_PHONE_STATE).subscribe(granted -> {
            if (granted) {
                startActivity(new Intent(getActivity(), PackageActivity.class));
            } else {
                Toast.makeText(getActivity(), "没有权限将无法获取单个app的流量信息", Toast.LENGTH_SHORT).show();
            }
        });
    } else if (view.getId() == R.id.btn_antivirus) {
        startActivity(new Intent(getActivity(), AntivirusActivity.class));
    } else if (view.getId() == R.id.btn_toast) {
        startActivity(new Intent(getActivity(), ToastActivity.class));
    } else if (view.getId() == R.id.btn_setting) {
        Uri packageUri = Uri.parse(String.format("package:%s", BuildConfig.APPLICATION_ID));
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageUri);
        startActivity(intent);
    } else if (view.getId() == R.id.btn_setting2) {
        gotoRomSettings();
    } else if (view.getId() == R.id.kotlin_coroutines) {
        startActivity(new Intent(getActivity(), FileActivity.class));
    }
}
Also used : RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) PackageActivity(com.yumore.navigate.activity.PackageActivity) ToastActivity(com.yumore.navigate.toast.ToastActivity) Intent(android.content.Intent) Uri(android.net.Uri)

Example 2 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project Android-Video-Trimmer by iknow4.

the class VideoSelectActivity method initUI.

@SuppressLint("CheckResult")
@Override
public void initUI() {
    mVideoLoadManager = new VideoLoadManager();
    mVideoLoadManager.setLoader(new VideoCursorLoader());
    mBinding = DataBindingUtil.setContentView(this, R.layout.activity_video_select);
    mCameraSurfaceViewLy = findViewById(R.id.layout_surface_view);
    mBinding.mBtnBack.setOnClickListener(this);
    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE).subscribe(granted -> {
        if (granted) {
            // Always true pre-M
            mVideoLoadManager.load(this, new SimpleCallback() {

                @Override
                public void success(Object obj) {
                    if (mVideoSelectAdapter == null) {
                        mVideoSelectAdapter = new VideoSelectAdapter(VideoSelectActivity.this, (Cursor) obj);
                    } else {
                        mVideoSelectAdapter.swapCursor((Cursor) obj);
                    }
                    if (mBinding.videoGridview.getAdapter() == null) {
                        mBinding.videoGridview.setAdapter(mVideoSelectAdapter);
                    }
                    mVideoSelectAdapter.notifyDataSetChanged();
                }
            });
        } else {
            finish();
        }
    });
    if (rxPermissions.isGranted(Manifest.permission.CAMERA)) {
        initCameraPreview();
    } else {
        mBinding.cameraPreviewLy.setVisibility(View.GONE);
        mBinding.openCameraPermissionLy.setVisibility(View.VISIBLE);
        mBinding.mOpenCameraPermission.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                rxPermissions.request(Manifest.permission.CAMERA).subscribe(granted -> {
                    if (granted) {
                        initCameraPreview();
                    }
                });
            }
        });
    }
}
Also used : VideoLoadManager(com.iknow.android.features.select.loader.VideoLoadManager) RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) R(com.iknow.android.R) SimpleCallback(iknow.android.utils.callback.SimpleCallback) Intent(android.content.Intent) VideoLoadManager(com.iknow.android.features.select.loader.VideoLoadManager) ViewGroup(android.view.ViewGroup) VideoRecordActivity(com.iknow.android.features.record.VideoRecordActivity) VideoCursorLoader(com.iknow.android.features.select.loader.VideoCursorLoader) Manifest(android.Manifest) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable) View(android.view.View) BaseActivity(com.iknow.android.features.common.ui.BaseActivity) PreviewSurfaceView(com.iknow.android.features.record.view.PreviewSurfaceView) ActivityVideoSelectBinding(com.iknow.android.databinding.ActivityVideoSelectBinding) Cursor(android.database.Cursor) DataBindingUtil(androidx.databinding.DataBindingUtil) RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) VideoCursorLoader(com.iknow.android.features.select.loader.VideoCursorLoader) Cursor(android.database.Cursor) View(android.view.View) PreviewSurfaceView(com.iknow.android.features.record.view.PreviewSurfaceView) SimpleCallback(iknow.android.utils.callback.SimpleCallback) SuppressLint(android.annotation.SuppressLint)

Example 3 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project AndroidQuick by ddnosh.

the class PermissionFragment method rxPermissionsCheck.

private void rxPermissionsCheck() {
    rxPermissions = new RxPermissions(this);
    rxPermissions.request(Manifest.permission.CAMERA).subscribe(granted -> {
        if (granted) {
            // Always true pre-M
            ToastUtil.showToast("授权成功!");
        } else {
            ToastUtil.showToast("授权失败!");
        }
    });
}
Also used : RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions)

Example 4 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project BigImageViewer by Piasy.

the class LongImageActivity method saveImage.

@SuppressWarnings("MissingPermission")
private void saveImage() {
    disposePermissionRequest();
    mPermissionRequest = new RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Consumer<Boolean>() {

        @Override
        public void accept(Boolean granted) throws Exception {
            if (granted) {
                mBigImageView.saveImageIntoGallery();
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            throwable.printStackTrace();
        }
    });
}
Also used : RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) Consumer(io.reactivex.functions.Consumer)

Example 5 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project RxPermissions by tbruyelle.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions.setLogging(true);
    setContentView(R.layout.act_main);
    surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    RxJavaInterop.toV2Observable(RxView.clicks(findViewById(R.id.enableCamera)).map(new Func1<Void, Object>() {

        @Override
        public Object call(final Void aVoid) {
            return new Object();
        }
    })).compose(rxPermissions.ensureEach(permission.CAMERA)).subscribe(new Consumer<Permission>() {

        @Override
        public void accept(Permission permission) {
            Log.i(TAG, "Permission result " + permission);
            if (permission.granted) {
                releaseCamera();
                camera = Camera.open(0);
                try {
                    camera.setPreviewDisplay(surfaceView.getHolder());
                    camera.startPreview();
                } catch (IOException e) {
                    Log.e(TAG, "Error while trying to display the camera preview", e);
                }
            } else if (permission.shouldShowRequestPermissionRationale) {
                // Denied permission without ask never again
                Toast.makeText(MainActivity.this, "Denied permission without ask never again", Toast.LENGTH_SHORT).show();
            } else {
                // Denied permission with ask never again
                // Need to go to the settings
                Toast.makeText(MainActivity.this, "Permission denied, can't enable the camera", Toast.LENGTH_SHORT).show();
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable t) {
            Log.e(TAG, "onError", t);
        }
    }, new Action() {

        @Override
        public void run() {
            Log.i(TAG, "OnComplete");
        }
    });
}
Also used : Action(io.reactivex.functions.Action) RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) Permission(com.tbruyelle.rxpermissions2.Permission) IOException(java.io.IOException) Func1(rx.functions.Func1)

Aggregations

RxPermissions (com.tbruyelle.rxpermissions2.RxPermissions)31 Intent (android.content.Intent)8 SuppressLint (android.annotation.SuppressLint)6 Permission (com.tbruyelle.rxpermissions2.Permission)4 View (android.view.View)3 GifSizeFilter (com.connxun.ltcx.utils.GifSizeFilter)3 RxPermissions (com.tbruyelle.rxpermissions3.RxPermissions)3 Manifest (android.Manifest)2 Uri (android.net.Uri)2 Button (android.widget.Button)2 OnClick (butterknife.OnClick)2 GlideEngine (com.zhihu.matisse.engine.impl.GlideEngine)2 CaptureStrategy (com.zhihu.matisse.internal.entity.CaptureStrategy)2 Consumer (io.reactivex.functions.Consumer)2 IOException (java.io.IOException)2 Activity (android.app.Activity)1 Context (android.content.Context)1 ActivityInfo (android.content.pm.ActivityInfo)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1