permissions-dispatcher / androidannotationspermissionsdispatcherplugin Goto Github PK
View Code? Open in Web Editor NEWPlugin for AndroidAnnotations allowing to use it together with PermissionsDispatcher
License: Apache License 2.0
Plugin for AndroidAnnotations allowing to use it together with PermissionsDispatcher
License: Apache License 2.0
Hi AleksanderMielczarek:
i have apply 'com.github.AleksanderMielczarek:AndroidAnnotationsPermissionsDispatcherPlugin:0.1.0' int the gradle, when compile the project, the XXXActivityPermissionsDispatcher is missing :( ,please tell me how to solve that ...
I'm using AA 4.4.0 and Kotlin.
Cannot access 'methodExample: it is protected in 'ActivityTools'
ActivityTools_.java:155: error: cannot find symbol
ActivityToolsPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
^
symbol: variable ActivityToolsPermissionsDispatcher
location: class ActivityTools_
I don't know if this is related to #15 , doesn't this plugin support Kotlin at all?
Dependencies:
def AAVersion = "4.4.0"
dependencies {
// ...
// AA
kapt "org.androidannotations:androidannotations:$AAVersion"
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation "com.github.hotchemi:permissionsdispatcher:3.0.1"
kapt "com.github.hotchemi:permissionsdispatcher-processor:3.0.1"
kapt "com.github.AleksanderMielczarek:AndroidAnnotationsPermissionsDispatcherPlugin:2.1.0"
}
Plugin needs to support Kotlin:
@hotchemi did I miss something?
I use AndroidAnnotations and added all dependencies you mentioned, but the class MainFragmentPermissionsDispatcher as described here: https://github.com/hotchemi/PermissionsDispatcher
is not generated if I use it on an EFragment called MainFragment...
Any idea why this doesn't work?
Other dependencies (e. g. lombok) do work with apt xxx :|
I use the current gradle plugin version.
Code sample:
app gradle
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 24
buildToolsVersion "$androidBuildVersion"
defaultConfig {
applicationId "xx.xxxxx"
minSdkVersion 21
targetSdkVersion 24
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
maven {
url "https://jitpack.io"
}
}
dataBinding {
enabled = true
}
}
dependencies {
// Android permissions
compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'
apt 'com.github.hotchemi:permissionsdispatcher-processor:2.1.3'
compile 'org.androidannotations:androidannotations-api:4.0.0'
apt 'org.androidannotations:androidannotations:4.0.0'
apt 'com.github.AleksanderMielczarek:AndroidAnnotationsPermissionsDispatcherPlugin:0.1.0'
}
project gradle
ext {
//dependencies
androidAnnotationsVersion = '4.0.0'
androidSupportVersion = '25.0.1'
androidBuildVersion = '25.0.1'
couchbaseVersion = '1.3.1'
lombokVersion = '1.16.8'
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
OneMediaFragment
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.couchbase.lite.CouchbaseLiteException;
import com.squareup.picasso.Picasso;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.FragmentArg;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.StringRes;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.io.File;
import java.io.FileNotFoundException;
import eu.eatable.PersistentEatableManager;
import eu.eatable.R;
import eu.eatable.events.ChangeBackgroundEvent;
import eu.eatable.events.ErrorEvent;
import eu.eatable.events.GetMediaEvent;
import eu.eatable.events.MediaEvent;
import eu.eatable.persistence.Media;
import eu.eatable.persistence.OneMediaField;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnNeverAskAgain;
import permissions.dispatcher.OnPermissionDenied;
import permissions.dispatcher.RuntimePermissions;
import pl.aprilapps.easyphotopicker.DefaultCallback;
import pl.aprilapps.easyphotopicker.EasyImage;
@RuntimePermissions
@EFragment(R.layout.fragment_onemedia)
public class OneMediaFragment extends Fragment {
@FragmentArg
OneMediaField oneMediaField;
@Bean
PersistentEatableManager eatableManager;
@StringRes(R.string.error_camera_denied)
String cameraDenied;
@StringRes(R.string.error_storage_denied)
String storageDenied;
@StringRes(R.string.error_never_ask)
String NeverAsked;
@StringRes(R.string.error_image_loading)
String ImageLoading;
@ViewById
View camera;
@ViewById
View gallery;
@ViewById
View document;
@ViewById
View mediaDelete;
@AfterViews
public void setup() {
this.camera.setOnClickListener(event -> {
openMedia(EasyImage.ImageSource.CAMERA);
});
this.gallery.setOnClickListener(event -> openMedia(EasyImage.ImageSource.GALLERY));
this.document.setOnClickListener(event -> openMedia(EasyImage.ImageSource.DOCUMENTS));
this.mediaDelete.setOnClickListener(event -> onImageDeleted());
}
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
EasyImage.handleActivityResult(requestCode, resultCode, data, this.getActivity(), new DefaultCallback() {
@Override
public void onImagePickerError(final Exception e, final EasyImage.ImageSource source, final int type) {
//Some error handling
Toast.makeText(OneMediaFragment.this.getContext(), getString(R.string.error_image_loading), Toast.LENGTH_SHORT).show();
}
@Override
public void onImagePicked(final File imageFile, final EasyImage.ImageSource source, final int type) {
//Handle the image
try {
;
} catch (CouchbaseLiteException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
@Override
public void onCanceled(final EasyImage.ImageSource source, final int type) {
//Cancel handling, you might wanna remove taken photo if it was canceled
if (source == EasyImage.ImageSource.CAMERA) {
final File photoFile = EasyImage.lastlyTakenButCanceledPhoto(getContext());
if (photoFile != null) photoFile.delete();
}
}
});
}
@NeedsPermission(value = {Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE})
public void openMedia(final EasyImage.ImageSource media) {
switch (media) {
case CAMERA:
EasyImage.openCamera(this, 0);
break;
case GALLERY:
EasyImage.openGallery(this, 0);
break;
case DOCUMENTS:
EasyImage.openDocuments(this, 0);
break;
}
}
@OnPermissionDenied(Manifest.permission.CAMERA)
public void showDeniedForCamera() {
EventBus.getDefault().post(new ErrorEvent(this.cameraDenied));
}
@OnNeverAskAgain(Manifest.permission.CAMERA)
public void showNeverAskForCamera() {
EventBus.getDefault().post(new ErrorEvent(this.NeverAsked));
}
@OnPermissionDenied(Manifest.permission.WRITE_EXTERNAL_STORAGE)
public void showDeniedForStorage() {
EventBus.getDefault().post(new ErrorEvent(this.storageDenied));
}
@OnNeverAskAgain(Manifest.permission.WRITE_EXTERNAL_STORAGE)
public void showNeverAskForStorage() {
EventBus.getDefault().post(new ErrorEvent(this.NeverAsked));
}
}
I've deleted all irrelevant stuff and some AndroidAnnotations stuff because of overhead - it works, even with apt and lombok.
Cannot use with PermissionDispatcher library v3.0.1 , they have changed the generated method names therefore the generated class cannot find the method.
DashBoardActivityPermissionsDispatcher.startLocationUpdatesWithCheck(this); -> failed
Thanx Bro ๐
Hi, I would like to contribute to this plugin. I would like to make it more Active. It could directly wrap all the annotations used in Permissionsdispatcher and make a more natural interaction with AndroidAnnotations...
For instance, when annotating a method:
@NeedsPermission(Manifest.permission.CAMERA)
void showCamera() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.sample_content_fragment, CameraPreviewFragment.newInstance())
.addToBackStack("camera")
.commitAllowingStateLoss();
}
The plugin could let PermissionsDispatcher do its work, but instead of the user having to call the method
MainActivityPermissionsDispatcher.showCameraWithCheck(this);
the plugin can override the method showCamera and call it from there.. so for the user, he only has to call showCamera
and then the Permissiondispatcher method would be called
This could be done for each of the annotations supported by Permissiondispatcher.
I also would like to add this Plugin directly into the DecleX Framework, but built-in in the framework itself.
Hi!
My case is the following:
I have a BaseDetailFragment
, that contains some shared logic for my PhoneDetailFragment
and TabletDetailFragment
.
One of these things, is managing the options menu.
For a couple of my options items, I need certain permissions.
I would like to handle these with the PermissionDispatcher
.
I see the dispatcher is generated, however, it is not used by the AA generated PhoneDetailFragment_
.
Is there something I can do to make this work, or is this impossible?
My code looks like this:
@EFragment
@RuntimePermissions
@OptionsMenu(R.menu.detail_menu)
public abstract class BaseDetailFragment extends Fragment {
@OptionsItem(R.id.share)
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
protected void onShareClicked() {
// some code
}
}
@EFragment(R.layout.fragment_detail)
public class PhoneDetailFragment extends BaseDetailFragment {
//No other permissions needed here
}
Thanks in advance!
These are the permissions that I have in my app
I get the next error when trying to rebuild
@NeedsPermission({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
protected void goToSmtOnPermission() {
}
@OnShowRationale({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
void showRationaleForStorage() {
Toast.makeText(this, R.string.permission_storage_rationale, Toast.LENGTH_SHORT).show();
}
@OnPermissionDenied({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
void deniedActionForStorage() {
Toast.makeText(this, R.string.permission_storage_denied, Toast.LENGTH_SHORT).show();
}
Error:Execution failed for task ':AppName:compileIcecreamSandwichArmv7AppNameDebugJavaWithJavac'.
> permissions.dispatcher.processor.exception.WrongParametersException: Method 'showRationaleForStorage()' must declare parameters of type 'PermissionRequest'
Hello, I'm trying to use your PermissionsDispatcherPlugin on an app that I'm creating to be backwards compatible to Java 1.6
It looks like when the annotations create the matching generated source it is using the <> typing. Is there something I can do so that it uses the full "type name", vs just using the <> supported in java 1.7+
Example:
private static final class PickImagePermissionRequest implements PermissionRequest {
private final WeakReference<CropFragment> weakTarget;
private PickImagePermissionRequest(CropFragment target) {
this.weakTarget = new WeakReference<>(target);
}
HI, I am using latest version 2.0.1,
and one of my activity require the permission WRITE_SETTINGS,
the PermissionsDispatcher generated correctly with the method "onActivityResult".
static void onActivityResult(xxxActivity target, int requestCode) {
switch (requestCode) {
case REQUEST_WRITESETTINGS:
if (PermissionUtils.hasSelfPermissions(target, PERMISSION_WRITESETTINGS) || Settings.System.canWrite(target)) {
target.writeSettings();
} else {
target.showDeniedForWriteSettings();
}
break;
default:
break;
}
}
However the generated Activity_ override onRequestPermissionsResult instead of onActivityResult
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
xxxActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
permissionDispatcherCalled_ = false;
}
And because the PermissionsDispatcher does not have the method onRequestPermissionsResult, so it is marked as error.
When I using this plugin to enable permissions-dispatcher (PD) working with AA on my project, I met some issues with delegates and overrides auto generating (described at https://github.com/permissions-dispatcher/AndroidAnnotationsPermissionsDispatcherPlugin#migrating-to-2xx).
Please check out my issue example repo at: https://github.com/luongvo/AndroidAnnotationsPermissionsDispatcherPlugin/commit/f60f550e16191f962e6b1363c14530f0a45854a3
MainActivity
abstract class, MainActivityPermissionsDispatcher
will be generated, but no MainActivity_
, that's right.ChildMainActivity
without PD implemented, ChildMainActivityPermissionsDispatcher
will not be generated, but has ChildMainActivity_
. This plugin still generates delegates and overrides in ChildMainActivity_
. After processed, it failed with error: cannot find symbol variable ChildMainActivityPermissionsDispatcher
in ChildMainActivity_
.So:
ChildMainActivityPermissionsDispatcher
invoke in onRequestPermissionsResult
if it has no annotation, also for those methods which was annotated with @NeedsPermission
Just in case!
The upstream project changed the package name. permissions-dispatcher/PermissionsDispatcher#560
This plugin should follow that change as well.
After updating to 2.0.0 i get error:
Error:(107, 9) error: cannot find symbol variable SplashActivityPermissionsDispatcher
in the generated class
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.