Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Annotation triggered connectivity checking for Android

License

NotificationsYou must be signed in to change notification settings

jd-alexander/flender

Repository files navigation

Annotation triggered connectivity checking for Android - powered by Java's Aspect Oriented Programming Framework, AspectJ

Aren't you tired of doing this all over your code?

if(connectivityUtil.isConnected(context)){//do something}else{Toast.makeText(context,"Internet unavailable",LENGTH_SHORT).show();}

With Flender connectivity checking couldn't be easier. Just annoate your method with@InternetRequired and Flender does the rest. A toast will be shown if there's no internet available and the method won't execute.

@InternetRequiredpublicvoiddoSomething(){Log.v("Flender","this plugin rocks");}

Download

buildscript {  repositories {    mavenCentral()  }  dependencies {    classpath'com.github.jd-alexander:flender-plugin:1.0'  }}applyplugin:'com.android.application'applyplugin:'flender'

Usage

For connectivity checking to work Flender needs access to the current context so set it like this :Flender.init(this); preferably in your application class or base activity. Once that's done, annotate away!.

@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Flender.init(this);test();    }@InternetRequiredpublicvoidtest()    {Log.v("Flender","Only logs if internet is available");    }}

You can also check for WiFi and Mobile connectivity with these annotations

@WiFiRequired@MobileRequired

If for some reason you don't want toast to be shown eg. using Flender in a service class then simply pass silent as a parameter to the respective annotation

@WiFiRequired("Silent")@InternetRequired("Silent")

If you want to trigger custom actions based on the annotation being used you can use one of the listeners associated each annotation.

@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Flender.init(this);Flender.setInternetUnavailable(newInternetUnavailable() {@OverridepublicvoidflenderEvent() {materialDialog.show();            }        });test();    }@InternetRequiredpublicvoidtest()    {    }

Once these listeners are used toasts,won't be triggered.

Contribution

Please fork repository and contribute using pull requests.

Any contributions, large or small, major features, bug fixes, additional language translations, unit/integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.

License

Copyright 2016 Joel DeanLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at   http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

About

Annotation triggered connectivity checking for Android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp