-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/notifications-redesign
Conflicts: WordPress/src/main/java/org/wordpress/android/WordPress.java WordPress/src/main/java/org/wordpress/android/ui/WPActionBarActivity.java WordPress/src/main/java/org/wordpress/android/ui/notifications/FollowRow.java WordPress/src/main/res/values/strings.xml
- Loading branch information
Showing
10 changed files
with
227 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
WordPressUtils/src/main/java/org/wordpress/android/util/NetworkUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.wordpress.android.util; | ||
|
||
import android.content.Context; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
import android.os.Build; | ||
import android.provider.Settings; | ||
|
||
/** | ||
* requires android.permission.ACCESS_NETWORK_STATE | ||
*/ | ||
public class NetworkUtils { | ||
public static final int TYPE_UNKNOWN = -1; | ||
|
||
/** | ||
* returns information on the active network connection | ||
*/ | ||
private static NetworkInfo getActiveNetworkInfo(Context context) { | ||
if (context == null) { | ||
return null; | ||
} | ||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
if (cm == null) { | ||
return null; | ||
} | ||
// note that this may return null if no network is currently active | ||
return cm.getActiveNetworkInfo(); | ||
} | ||
|
||
/** | ||
* returns the ConnectivityManager.TYPE_xxx if there's an active connection, otherwise | ||
* returns TYPE_UNKNOWN | ||
*/ | ||
private static int getActiveNetworkType(Context context) { | ||
NetworkInfo info = getActiveNetworkInfo(context); | ||
if (info == null || !info.isConnected()) { | ||
return TYPE_UNKNOWN; | ||
} | ||
return info.getType(); | ||
} | ||
|
||
/** | ||
* returns true if a network connection is available | ||
*/ | ||
public static boolean isNetworkAvailable(Context context) { | ||
NetworkInfo info = getActiveNetworkInfo(context); | ||
return (info != null && info.isConnected()); | ||
} | ||
|
||
/** | ||
* returns true if the user is connected to WiFi | ||
*/ | ||
public static boolean isWiFiConnected(Context context) { | ||
return (getActiveNetworkType(context) == ConnectivityManager.TYPE_WIFI); | ||
} | ||
|
||
/** | ||
* returns true if airplane mode has been enabled | ||
*/ | ||
public static boolean isAirplaneModeOn(Context context) { | ||
// prior to JellyBean 4.2 this was Settings.System.AIRPLANE_MODE_ON, JellyBean 4.2 | ||
// moved it to Settings.Global | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; | ||
} else { | ||
return Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0; | ||
} | ||
} | ||
|
||
/** | ||
* returns true if there's an active network connection, otherwise displays a toast error | ||
* and returns false | ||
*/ | ||
public static boolean checkConnection(Context context) { | ||
if (isNetworkAvailable(context)) { | ||
return true; | ||
} | ||
ToastUtils.showToast(context, R.string.no_network_message); | ||
return false; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
WordPressUtils/src/main/java/org/wordpress/android/util/PackageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.wordpress.android.util; | ||
|
||
import android.content.Context; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
|
||
public class PackageUtils { | ||
/** | ||
* Return true if Debug build. false otherwise. | ||
*/ | ||
public static boolean isDebugBuild() { | ||
return BuildConfig.DEBUG; | ||
} | ||
|
||
public static PackageInfo getPackageInfo(Context context) { | ||
try { | ||
PackageManager manager = context.getPackageManager(); | ||
return manager.getPackageInfo(context.getPackageName(), 0); | ||
} catch (PackageManager.NameNotFoundException e) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Return version code, or 0 if it can't be read | ||
*/ | ||
public static int getVersionCode(Context context) { | ||
PackageInfo packageInfo = getPackageInfo(context); | ||
if (packageInfo != null) { | ||
return packageInfo.versionCode; | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
* Return version name, or the string "0" if it can't be read | ||
*/ | ||
public static String getVersionName(Context context) { | ||
PackageInfo packageInfo = getPackageInfo(context); | ||
if (packageInfo != null) { | ||
return packageInfo.versionName; | ||
} | ||
return "0"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.