-
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.
Browse files
Browse the repository at this point in the history
5b22440 Merge branch 'release/3.2' into develop 1a2a73f fix debug/release build propagation to sub projects d9eac2e Merge branch 'release/3.2' into develop 380ece6 Merge pull request #1861 from wordpress-mobile/feature/notifications-redesign c38f131 Merge pull request #1860 from wordpress-mobile/issue/1821-remove-istablet 4e92eaa Merge branch 'hotfix/3.1.2' into release/3.2 cbc7b24 fix #1821: remove DisplayUtis.isTablet() method 343771a Catch NPE in Bitmap.CreateBitmap and make sure the returned bitmap is not null c44a87a Merge branch 'release/3.2' into feature/notifications-redesign 97c557c Revert "Revert "Merge pull request #1799 from wordpress-mobile/feature/1795-reader-render-attachments"" 1cacaf2 Merge branch 'hotfix/3.1.1' into release/3.2 568782f Merge branch 'hotfix/3.1.1' into develop 96fd180 remove isTablet() check 870944d Merge branch 'release/3.2' into feature/notifications-redesign 3390393 Revert "Merge pull request #1799 from wordpress-mobile/feature/1795-reader-render-attachments" 03bbac0 Merge branch 'develop' into feature/notifications-redesign 8ec2915 Replaced String.format() with string concatenation in ReaderUtils and PhotonUtils after profiler showed String.format() to be hurting performance 1623d65 fix lint error in utils e273dd3 Merge branch 'develop' into feature/notifications-redesign 4bfc641 Removed aggressive `JSONUtil` logging f7f4556 update support-v13 library to version 19.1.0 fafcf67 Merge pull request #1781 from wordpress-mobile/issue/17760-reader-comment-full-images 1868cc5 disable refresh on the attacher 082c13f use the PTR library version 0.9.7 f21f5d3 set network refresh mode as default d262f8d remove unused code 9e592fd add a network mode in PullToRefreshHeaderTransformer to show a different message when network is disabled f85a003 move NetworkUtils to WPUtils subtree d19c080 Updated comment cabb8a7 TextView content is reset to itself to force it to correctly resize using cached image 48e4ed2 More cleanup 2426243 Cleanup WPImageGetter based on code analysis c955d26 Merge pull request #1764 from wordpress-mobile/issue/1713-send-version-code-to-mixpanel 3bc1080 Merge branch 'release/3.1' into develop caa9db0 fix #1762: show blog url in the share blog spinner if the blog title is an empty string e1eecbf remove ProfilingUtils.getVersionName calls 075b989 remove unused method from ProfilingUtils b48cbda move BuildUtils to WPUtils subtree, rename BuildUtils to PackageUtils and add getPackageInfo and getVersionCode methods git-subtree-dir: libs/utils git-subtree-split: 5b22440
- Loading branch information
Showing
14 changed files
with
256 additions
and
102 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
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
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
package org.wordpress.android.util; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
import android.os.Build; | ||
import android.os.Build.VERSION_CODES; | ||
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 | ||
*/ | ||
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1) | ||
@SuppressWarnings("deprecation") | ||
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.