Java Code Examples for androidx.core.content.ContextCompat#checkSelfPermission()

The following examples show how to use androidx.core.content.ContextCompat#checkSelfPermission() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogcatActivity.java    From matlog with GNU General Public License v3.0 6 votes vote down vote up
private void showSaveLogDialog() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                SAVE_LOG_REQUEST);
        return;
    }

    if (!SaveLogHelper.checkSdCard(this)) {
        return;
    }

    MaterialDialog.InputCallback onClickListener = (materialDialog, charSequence) -> {
        if (DialogHelper.isInvalidFilename(charSequence)) {
            Toast.makeText(LogcatActivity.this, R.string.enter_good_filename, Toast.LENGTH_SHORT).show();
        } else {
            String filename = charSequence.toString();
            saveLog(filename);
        }
    };

    DialogHelper.showFilenameSuggestingDialog(this, null, onClickListener, R.string.save_log);
}
 
Example 2
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 6 votes vote down vote up
private void askForPermission(String permission, Integer requestCode) {
    if (mActivity != null && ContextCompat.checkSelfPermission(mActivity, permission) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(mActivity, permission)) {

            //This is called if user has denied the permission before
            //In this case I am just asking the permission again
            ActivityCompat.requestPermissions(mActivity, new String[]{permission}, requestCode);

        } else {

            ActivityCompat.requestPermissions(mActivity, new String[]{permission}, requestCode);
        }
    }
}
 
Example 3
Source File: PBaseLoaderFragment.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 加载媒体文件夹
 */
protected void loadMediaSets() {
    if (getActivity() == null) {
        return;
    }
    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQ_STORAGE);
    } else {
        //从媒体库拿到文件夹列表
        ImagePicker.provideMediaSets(getActivity(), getSelectConfig().getMimeTypes(), new MediaSetsDataSource.MediaSetProvider() {
            @Override
            public void providerMediaSets(ArrayList<ImageSet> imageSets) {
                loadMediaSetsComplete(imageSets);
            }
        });
    }
}
 
Example 4
Source File: MainActivity.java    From ridesharing-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ObjectMapper mapper = new ObjectMapper();
    String json = MySharedPreferences.get(this).getString(MySharedPreferences.USER_KEY, "");
    try {
        user = mapper.readValue(json, User.class);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    if (user == null) return;

    if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)) {
        startMap();
    } else {
        startPermissionsRequest();
    }
}
 
Example 5
Source File: GroupChatFragment.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void showDownloadConfirmDialog(final FileMessage message) {
    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        // If storage permissions are not granted, request permissions at run-time,
        // as per < API 23 guidelines.
        requestStoragePermissions();
    } else {
        new AlertDialog.Builder(getActivity())
                .setMessage(getString(R.string.request_download_file))
                .setPositiveButton(R.string.download, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == DialogInterface.BUTTON_POSITIVE) {
                            FileUtils.downloadFile(getActivity(), message.getUrl(), message.getName());
                        }
                    }
                })
                .setNegativeButton(R.string.cancel, null).show();
    }

}
 
Example 6
Source File: PermissionUtils.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private void checkPermissions(@NonNull Context c) {
    pCalendar = ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(c, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED;
    pStorage = ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(c, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    pLocation = ContextCompat.checkSelfPermission(c, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
        pNotPolicy = nm.isNotificationPolicyAccessGranted();
        Crashlytics.setBool("pNotPolicy", pLocation);
    } else
        pNotPolicy = true;

    Crashlytics.setBool("pCalendar", pCalendar);
    Crashlytics.setBool("pStorage", pStorage);
    Crashlytics.setBool("pLocation", pLocation);
    Crashlytics.setBool("pNotPolicy", pNotPolicy);

}
 
Example 7
Source File: BaseFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 6 votes vote down vote up
public void requestPermission(int request, String... permissions) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        List<String> needrequest = new ArrayList<>();
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(getActivity(), permission)
                    != PackageManager.PERMISSION_GRANTED) {
                needrequest.add(permission);
            }
        }
        if (needrequest.size() > 0) {
            requestPermissions(needrequest.toArray(new String[needrequest.size()]), request);
            return;
        }
    }
    onPermissionGranted(request);
}
 
Example 8
Source File: BitmapLoadTask.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String getFilePath() {
    if (ContextCompat.checkSelfPermission(getContext(), permission.READ_EXTERNAL_STORAGE)
            == PackageManager.PERMISSION_GRANTED) {
        return FileUtils.getPath(getContext(), mInputUri);
    } else {
        return null;
    }
}
 
Example 9
Source File: TimeAttendantFastFragment.java    From iBeacon-Android with Apache License 2.0 5 votes vote down vote up
public boolean checkLocationPermission() {
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                Manifest.permission.ACCESS_FINE_LOCATION)) {

            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            new AlertDialog.Builder(getContext())
                    .setTitle(R.string.title_location_permission)
                    .setMessage(R.string.text_location_permission)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            //Prompt the user once explanation has been shown
                            ActivityCompat.requestPermissions(getActivity(),
                                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                    MY_PERMISSIONS_REQUEST_LOCATION);
                        }
                    })
                    .create()
                    .show();


        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(getActivity(),
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    MY_PERMISSIONS_REQUEST_LOCATION);
        }
        return false;
    } else {
        Log.i(TAG, "persmission granted");
        return true;
    }
}
 
Example 10
Source File: BaseActivity.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
public boolean requestPermission(String permission) {
    boolean isGranted = ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED;
    if (!isGranted) {
        ActivityCompat.requestPermissions(
                this,
                new String[]{permission},
                READ_WRITE_STORAGE);
    }
    return isGranted;
}
 
Example 11
Source File: BlurBenchmarkFragment.java    From BlurTestAndroid with Apache License 2.0 5 votes vote down vote up
private boolean checkHasReadStoragePermission() {
    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "permission not granted yet, show dialog");
        FragmentCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE_PERMISSION);
        return false;
    }
    Log.d(TAG, "permission already granted");
    return true;
}
 
Example 12
Source File: MicrophoneConfigureActivity.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
private void startMic () {
    String permission = Manifest.permission.RECORD_AUDIO;
    int requestCode = 999;
    if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

            //This is called if user has denied the permission before
            //In this case I am just asking the permission again
            ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);

        } else {

            ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
        }
    } else {

        try {
            microphone = MicrophoneTaskFactory.makeSampler(this);
            microphone.setMicListener(this);
            microphone.execute();
        } catch (MicrophoneTaskFactory.RecordLimitExceeded e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
 
Example 13
Source File: AndroidPermissions.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void requestPermissions(VoidBlock1<Collection<String>> notGrantedPermissions, String... permissions) {
    Collection<String> reqPermissions = new LinkedHashSet<>();
    if (permissions != null && permissions.length > 0) {
        for (String permission : permissions)
            if (permission != null) {
                permission = permission.trim();
                if (!permission.isEmpty()) {
                    if (ContextCompat.checkSelfPermission(MainActivity.current(), permission) != PackageManager.PERMISSION_GRANTED)
                        reqPermissions.add(permission);
                } else
                    Native.system().error("Requesting an empty Android permission", null);
            } else
                Native.system().error("Requesting a null Android permission", null);
    } else
        Native.system().error("Requested Android permissions are empty", null);
    Collection<String> alreadyAsked = BaseUtils.removeCommon(reqPermissions, alreadyAskedForPermission);
    alreadyAskedForPermission.addAll(reqPermissions);
    if (reqPermissions.isEmpty()) {
        if (notGrantedPermissions != null)
            notGrantedPermissions.invoke(alreadyAsked);
    } else {
        MainActivity.current.getStateListener().request((givenPermissions, grantResults) -> {
            if (givenPermissions == null || grantResults == null || notGrantedPermissions == null)
                return;
            for (int i = 0; i < givenPermissions.length && i < grantResults.length; i++)
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
                    reqPermissions.remove(givenPermissions[i]);
            notGrantedPermissions.invoke(reqPermissions);
        }, reqPermissions);
    }
}
 
Example 14
Source File: AccountImporter.java    From Android-SingleSignOn with GNU General Public License v3.0 5 votes vote down vote up
private static void checkAndroidAccountPermissions(Context context) throws AndroidGetAccountsPermissionNotGranted {
    // https://developer.android.com/reference/android/accounts/AccountManager#getAccountsByType(java.lang.String)
    // Caller targeting API level below Build.VERSION_CODES.O that have not been granted the 
    // Manifest.permission.GET_ACCOUNTS permission, will only see those accounts managed by 
    // AbstractAccountAuthenticators whose signature matches the client.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        // Do something for lollipop and above versions
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
            Log.e(TAG, "Permission not granted yet!");
            throw new AndroidGetAccountsPermissionNotGranted();
        } else {
            Log.d(TAG, "Permission granted!");
        }
    }
}
 
Example 15
Source File: DJIDemoApplication.java    From Android-GSDemo-GoogleMap with MIT License 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mHandler = new Handler(Looper.getMainLooper());

    /**
     * When starting SDK services, an instance of interface DJISDKManager.DJISDKManagerCallback will be used to listen to
     * the SDK Registration result and the product changing.
     */
    mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {

        //Listens to the SDK registration result
        @Override
        public void onRegister(DJIError error) {

            if(error == DJISDKError.REGISTRATION_SUCCESS) {

                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register Success", Toast.LENGTH_LONG).show();
                    }
                });

                DJISDKManager.getInstance().startConnectionToProduct();

            } else {

                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register sdk fails, check network is available", Toast.LENGTH_LONG).show();
                    }
                });

            }
            Log.e("TAG", error.toString());
        }

        @Override
        public void onProductDisconnect() {
            Log.d("TAG", "onProductDisconnect");
            notifyStatusChange();
        }
        @Override
        public void onProductConnect(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductConnect newProduct:%s", baseProduct));
            notifyStatusChange();

        }
        @Override
        public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent,
                                      BaseComponent newComponent) {
            if (newComponent != null) {
                newComponent.setComponentListener(new BaseComponent.ComponentListener() {

                    @Override
                    public void onConnectivityChange(boolean isConnected) {
                        Log.d("TAG", "onComponentConnectivityChanged: " + isConnected);
                        notifyStatusChange();
                    }
                });
            }

            Log.d("TAG",
                    String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s",
                            componentKey,
                            oldComponent,
                            newComponent));

        }
        @Override
        public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {

        }

        @Override
        public void onDatabaseDownloadProgress(long l, long l1) {

        }
    };
    //Check the permissions before registering the application for android system 6.0 above.
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (permissionCheck == 0 && permissionCheck2 == 0)) {
        //This is used to start SDK services and initiate SDK.
        DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
        Toast.makeText(getApplicationContext(), "registering, pls wait...", Toast.LENGTH_LONG).show();

    } else {
        Toast.makeText(getApplicationContext(), "Please check if the permission is granted.", Toast.LENGTH_LONG).show();
    }

}
 
Example 16
Source File: AppUtils.java    From react-native-baidu-map with MIT License 4 votes vote down vote up
public static boolean hasPermission(Activity activity, String permission) {
    return ContextCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED;
}
 
Example 17
Source File: Permissions.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
static private void checkEventLocation(Context context, Event event, ArrayList<PermissionType>  permissions) {
    if (event == null) return; // true;
    //if (android.os.Build.VERSION.SDK_INT >= 23) {
        try {
            if ((event._eventPreferencesWifi._enabled &&
                    ((event._eventPreferencesWifi._connectionType == EventPreferencesWifi.CTYPE_NEARBY) ||
                     (event._eventPreferencesWifi._connectionType == EventPreferencesWifi.CTYPE_NOT_NEARBY))) ||
                (event._eventPreferencesBluetooth._enabled &&
                    ((event._eventPreferencesBluetooth._connectionType == EventPreferencesBluetooth.CTYPE_NEARBY) ||
                     (event._eventPreferencesBluetooth._connectionType == EventPreferencesBluetooth.CTYPE_NOT_NEARBY))) ||
                (event._eventPreferencesLocation._enabled) ||
                (event._eventPreferencesMobileCells._enabled) ||
                (event._eventPreferencesTime._enabled &&
                    (event._eventPreferencesTime._timeType != EventPreferencesTime.TIME_TYPE_EXACT))) {
                boolean grantedAccessCoarseLocation = ContextCompat.checkSelfPermission(context, permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
                boolean grantedAccessFineLocation = ContextCompat.checkSelfPermission(context, permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
                boolean grantedAccessBackgroundLocation = (Build.VERSION.SDK_INT < 29) || ContextCompat.checkSelfPermission(context, permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
                if (permissions != null) {
                    if (event._eventPreferencesWifi._enabled &&
                            ((event._eventPreferencesWifi._connectionType == EventPreferencesWifi.CTYPE_NEARBY) ||
                                    (event._eventPreferencesWifi._connectionType == EventPreferencesWifi.CTYPE_NOT_NEARBY))) {
                        if (!grantedAccessCoarseLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_WIFI_PREFERENCES, permission.ACCESS_COARSE_LOCATION));
                        if (!grantedAccessFineLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_WIFI_PREFERENCES, permission.ACCESS_FINE_LOCATION));
                        if (!grantedAccessBackgroundLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_WIFI_PREFERENCES, permission.ACCESS_BACKGROUND_LOCATION));
                    }
                    else
                    if (event._eventPreferencesBluetooth._enabled &&
                            ((event._eventPreferencesBluetooth._connectionType == EventPreferencesBluetooth.CTYPE_NEARBY) ||
                                    (event._eventPreferencesBluetooth._connectionType == EventPreferencesBluetooth.CTYPE_NOT_NEARBY))) {
                        if (!grantedAccessCoarseLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_BLUETOOTH_PREFERENCES, permission.ACCESS_COARSE_LOCATION));
                        if (!grantedAccessFineLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_BLUETOOTH_PREFERENCES, permission.ACCESS_FINE_LOCATION));
                        if (!grantedAccessBackgroundLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_BLUETOOTH_PREFERENCES, permission.ACCESS_BACKGROUND_LOCATION));
                    }
                    else
                    if (event._eventPreferencesMobileCells._enabled) {
                        if (!grantedAccessCoarseLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_MOBILE_CELLS_PREFERENCES, permission.ACCESS_COARSE_LOCATION));
                        if (!grantedAccessFineLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_MOBILE_CELLS_PREFERENCES, permission.ACCESS_FINE_LOCATION));
                        if (!grantedAccessBackgroundLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_MOBILE_CELLS_PREFERENCES, permission.ACCESS_BACKGROUND_LOCATION));
                    }
                    else
                    if (event._eventPreferencesTime._enabled) {
                        if (!grantedAccessCoarseLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_TIME_PREFERENCES, permission.ACCESS_COARSE_LOCATION));
                        if (!grantedAccessFineLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_TIME_PREFERENCES, permission.ACCESS_FINE_LOCATION));
                        if (!grantedAccessBackgroundLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_TIME_PREFERENCES, permission.ACCESS_BACKGROUND_LOCATION));
                    }
                    else {
                        if (!grantedAccessCoarseLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_LOCATION_PREFERENCES, permission.ACCESS_COARSE_LOCATION));
                        if (!grantedAccessFineLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_LOCATION_PREFERENCES, permission.ACCESS_FINE_LOCATION));
                        if (!grantedAccessBackgroundLocation)
                            permissions.add(new PermissionType(PERMISSION_EVENT_LOCATION_PREFERENCES, permission.ACCESS_BACKGROUND_LOCATION));
                    }
                }
                //return grantedAccessCoarseLocation && grantedAccessFineLocation;
            } //else
                //return true;
        } catch (Exception e) {
            //return false;
        }
    //}
    /*else {
        try {
            if ((event._eventPreferencesWifi._enabled &&
                    ((event._eventPreferencesWifi._connectionType == EventPreferencesWifi.CTYPE_NEARBY) ||
                     (event._eventPreferencesWifi._connectionType == EventPreferencesWifi.CTYPE_NOT_NEARBY))) ||
                (event._eventPreferencesBluetooth._enabled &&
                    ((event._eventPreferencesBluetooth._connectionType == EventPreferencesBluetooth.CTYPE_NEARBY) ||
                     (event._eventPreferencesBluetooth._connectionType == EventPreferencesBluetooth.CTYPE_NOT_NEARBY))) ||
                (event._eventPreferencesLocation._enabled) ||
                (event._eventPreferencesMobileCells._enabled) ||
                (event._eventPreferencesTime._enabled &&
                    (event._eventPreferencesTime._timeType != EventPreferencesTime.TIME_TYPE_EXACT))) {
                return hasPermission(context, permission.ACCESS_COARSE_LOCATION) &&
                        hasPermission(context, permission.ACCESS_FINE_LOCATION);
            } else
                return true;
        } catch (Exception e) {
            return false;
        }
    }*/
}
 
Example 18
Source File: PiePolylineChartActivity.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.viewGithub: {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java"));
            startActivity(i);
            break;
        }
        case R.id.actionToggleValues: {
            for (IDataSet<?> set : chart.getData().getDataSets())
                set.setDrawValues(!set.isDrawValuesEnabled());

            chart.invalidate();
            break;
        }
        case R.id.actionToggleHole: {
            if (chart.isDrawHoleEnabled())
                chart.setDrawHoleEnabled(false);
            else
                chart.setDrawHoleEnabled(true);
            chart.invalidate();
            break;
        }
        case R.id.actionToggleMinAngles: {
            if (chart.getMinAngleForSlices() == 0f)
                chart.setMinAngleForSlices(36f);
            else
                chart.setMinAngleForSlices(0f);
            chart.notifyDataSetChanged();
            chart.invalidate();
            break;
        }
        case R.id.actionToggleCurvedSlices: {
            boolean toSet = !chart.isDrawRoundedSlicesEnabled() || !chart.isDrawHoleEnabled();
            chart.setDrawRoundedSlices(toSet);
            if (toSet && !chart.isDrawHoleEnabled()) {
                chart.setDrawHoleEnabled(true);
            }
            if (toSet && chart.isDrawSlicesUnderHoleEnabled()) {
                chart.setDrawSlicesUnderHole(false);
            }
            chart.invalidate();
            break;
        }
        case R.id.actionDrawCenter: {
            if (chart.isDrawCenterTextEnabled())
                chart.setDrawCenterText(false);
            else
                chart.setDrawCenterText(true);
            chart.invalidate();
            break;
        }
        case R.id.actionToggleXValues: {

            chart.setDrawEntryLabels(!chart.isDrawEntryLabelsEnabled());
            chart.invalidate();
            break;
        }
        case R.id.actionTogglePercent:
            chart.setUsePercentValues(!chart.isUsePercentValuesEnabled());
            chart.invalidate();
            break;
        case R.id.animateX: {
            chart.animateX(1400);
            break;
        }
        case R.id.animateY: {
            chart.animateY(1400);
            break;
        }
        case R.id.animateXY: {
            chart.animateXY(1400, 1400);
            break;
        }
        case R.id.actionToggleSpin: {
            chart.spin(1000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic);
            break;
        }
        case R.id.actionSave: {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                saveToGallery();
            } else {
                requestStoragePermission(chart);
            }
            break;
        }
    }
    return true;
}
 
Example 19
Source File: WelcomeActivity.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
public static boolean hasStoragePermission(Activity activity) {
    String storagePermission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    int hasPermission = ContextCompat.checkSelfPermission(activity, storagePermission);
    return (hasPermission == PackageManager.PERMISSION_GRANTED);
}
 
Example 20
Source File: Permissions.java    From ExoVideoView with Apache License 2.0 4 votes vote down vote up
public static boolean canReadStorage(Context context) {
    return !AndroidUtil.isMarshMallowOrLater() || ContextCompat.checkSelfPermission(context,
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}