Skip to content

Commit

Permalink
Added v1.02
Browse files Browse the repository at this point in the history
  • Loading branch information
alkathirikhalid committed Sep 18, 2017
1 parent cfd748d commit 73d14d0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public abstract class ConnectionActivity extends Activity implements ConnectionC
/**
* <p>Connection Change Broadcast Receiver.</p>
*/
protected ConnectionChange connectionChange;
private ConnectionChange connectionChange;

/**
* <p>Structured description of Intent values to be matched.</p>
*/
protected IntentFilter intentFilter;
private IntentFilter intentFilter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public abstract class ConnectionAppCompactActivity extends AppCompatActivity imp
/**
* <p>Connection Change Broadcast Receiver.</p>
*/
protected ConnectionChange connectionChange;
private ConnectionChange connectionChange;

/**
* <p>Structured description of Intent values to be matched.</p>
*/
protected IntentFilter intentFilter;
private IntentFilter intentFilter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
100 changes: 39 additions & 61 deletions app/src/main/java/com/alkathirikhalid/util/ConnectionChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,26 @@
* @version 1.02
*/

public class ConnectionChange extends BroadcastReceiver {
class ConnectionChange extends BroadcastReceiver {

/**
* <p>An Interface that provides a Call Back Mechanism to be notified
* when Connection Change has taken place.</p>
*/
private ConnectionChangeListener connectionChangeListener;

/**
* <p>Default Constructor adhering to Observer Pattern.</p>
* To be used with <code>setConnectionChangeListener</code>.
*/
public ConnectionChange() {
}

/**
* <p>Constructor adhering to Observer Pattern.</p>
* To be used after <code>ConnectionChange()</code>.
*
* @param connectionChangeListener The Connection Change Call Back.
* @return The Initialized linked Connection Change Call Back.
*/
public ConnectionChange setConnectionChangeListener(ConnectionChangeListener connectionChangeListener) {
ConnectionChange setConnectionChangeListener(ConnectionChangeListener connectionChangeListener) {
this.connectionChangeListener = connectionChangeListener;
return this;
}

/**
* <p>Constructor adhering to Delegation Pattern.</p>
* Only used after <code>implements</code> <code>ConnectionChangeListener</code>.
*
* @param connectionChangeListener The Connection Change Call Back.
*/
public ConnectionChange(ConnectionChangeListener connectionChangeListener) {
this.connectionChangeListener = connectionChangeListener;
}

/**
* This method is called when the BroadcastReceiver is receiving an Intent
* broadcast. During this time you can use the other methods on
Expand Down Expand Up @@ -100,48 +83,43 @@ public ConnectionChange(ConnectionChangeListener connectionChangeListener) {
*/
@Override
public void onReceive(Context context, Intent intent) {
/*
* Provide real time values by ignoring the value that was last broadcast
* and is currently held in the sticky cache
*/
if (!isInitialStickyBroadcast()) {
// Checks if there are linked listeners before invoking change
if (connectionChangeListener != null) {
// Checks if there is connectivity or is in the process of being established
if (Connection.isConnectedOrConnecting(context)) {
// Notifies there is connectivity or is in the process of being established
connectionChangeListener.connectedOrConnecting();
}
// Checks if there is connectivity and it is possible to pass data
if (Connection.isConnected(context)) {
// Notifies there is connectivity and it is possible to pass data
connectionChangeListener.connected();
}
// Checks if there is connectivity to WIFI
if (Connection.isTypeWifi(context)) {
// Notifies there is connectivity to WIFI
connectionChangeListener.typeWifi();
}
// Checks if there is connectivity to MOBILE
if (Connection.isTypeMobile(context)) {
// Notifies there is connectivity to MOBILE
connectionChangeListener.typeMobile();
}
// Checks if there is connectivity to MOBILE data speed of about 400kbps to 23Mbps
if (Connection.isConnectedConnectionFast(context)) {
// Notifies there is connectivity to MOBILE data speed of about 400kbps to 23Mbps
connectionChangeListener.connectedConnectionFast();
}
// Checks if there is connectivity to MOBILE data speed of about 14kbps to 100kbps
if (Connection.isConnectedConnectionSlow(context)) {
// Notifies there is connectivity to MOBILE data speed of about 14kbps to 100kbps
connectionChangeListener.connectedConnectionSlow();
}
// Checks there is no connectivity
if (!Connection.isConnectedOrConnecting(context)) {
// Notifies there is no connectivity
connectionChangeListener.noNetwork();
}

// Checks if there are linked listeners before invoking change
if (connectionChangeListener != null) {
// Checks if there is connectivity or is in the process of being established
if (Connection.isConnectedOrConnecting(context)) {
// Notifies there is connectivity or is in the process of being established
connectionChangeListener.connectedOrConnecting();
}
// Checks if there is connectivity and it is possible to pass data
if (Connection.isConnected(context)) {
// Notifies there is connectivity and it is possible to pass data
connectionChangeListener.connected();
}
// Checks if there is connectivity to WIFI
if (Connection.isTypeWifi(context)) {
// Notifies there is connectivity to WIFI
connectionChangeListener.typeWifi();
}
// Checks if there is connectivity to MOBILE
if (Connection.isTypeMobile(context)) {
// Notifies there is connectivity to MOBILE
connectionChangeListener.typeMobile();
}
// Checks if there is connectivity to MOBILE data speed of about 400kbps to 23Mbps
if (Connection.isConnectedConnectionFast(context)) {
// Notifies there is connectivity to MOBILE data speed of about 400kbps to 23Mbps
connectionChangeListener.connectedConnectionFast();
}
// Checks if there is connectivity to MOBILE data speed of about 14kbps to 100kbps
if (Connection.isConnectedConnectionSlow(context)) {
// Notifies there is connectivity to MOBILE data speed of about 14kbps to 100kbps
connectionChangeListener.connectedConnectionSlow();
}
// Checks there is no connectivity
if (!Connection.isConnectedOrConnecting(context)) {
// Notifies there is no connectivity
connectionChangeListener.noNetwork();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @version 1.02
*/

public interface ConnectionChangeListener {
interface ConnectionChangeListener {

/**
* <p>Notify there is connectivity or is in the process of being established.</p>
Expand Down

0 comments on commit 73d14d0

Please sign in to comment.