Skip to content

Commit

Permalink
Merge branch 'develop' into feature/notifications-redesign
Browse files Browse the repository at this point in the history
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
roundhill committed Aug 29, 2014
2 parents eff81c0 + 0868a89 commit 5026c92
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 81 deletions.
7 changes: 3 additions & 4 deletions WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.github.castorflex.smoothprogressbar:library:0.4.0'
compile 'org.wordpress:pulltorefresh-main:+@aar' // org.wordpress version includes some fixes
compile 'com.android.support:support-v13:19.0.+'
compile 'org.wordpress:pulltorefresh-main:0.9.7@aar' // org.wordpress version includes some fixes
compile 'com.android.support:support-v13:19.1.0'
}

android {
Expand All @@ -32,8 +32,7 @@ android {

defaultConfig {
applicationId "org.wordpress.android.util"
versionName "1.1.0"
versionCode 1
versionName "1.2.0"
minSdkVersion 14
targetSdkVersion 19
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static ArrayList<String> toHtmlList(Context context) {
ArrayList<String> items = new ArrayList<String>();

// add version & device info - be sure to change HEADER_LINE_COUNT if additional lines are added
items.add("<strong>WordPress Android version: " + ProfilingUtils.getVersionName(context) + "</strong>");
items.add("<strong>WordPress Android version: " + PackageUtils.getVersionName(context) + "</strong>");
items.add("<strong>Android device name: " + DeviceUtils.getInstance().getDeviceName(context) + "</strong>");

Iterator<LogEntry> it = mLogEntries.iterator();
Expand All @@ -193,7 +193,7 @@ public static String toPlainText(Context context) {
StringBuilder sb = new StringBuilder();

// add version & device info
sb.append("WordPress Android version: " + ProfilingUtils.getVersionName(context)).append("\n")
sb.append("WordPress Android version: " + PackageUtils.getVersionName(context)).append("\n")
.append("Android device name: " + DeviceUtils.getInstance().getDeviceName(context)).append("\n\n");

Iterator<LogEntry> it = mLogEntries.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ public int compare(Object blog1, Object blog2) {
return blogName1.compareToIgnoreCase(blogName2);
}
};

/**
* Return a blog name or blog url (host part only) if trimmed name is an empty string
*/
public static String getBlogNameFromAccountMap(Map<String, Object> account) {
String blogName = StringUtils.unescapeHTML(MapUtils.getMapStr(account, "blogName"));
if (blogName.trim().length() == 0) {
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
}
return blogName;
}
}
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;
}
}
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";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.wordpress.android.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.SystemClock;

import org.wordpress.android.util.AppLog.T;
Expand Down Expand Up @@ -76,16 +73,5 @@ public void dumpToLog() {
}
AppLog.d(T.PROFILING, mLabel + ": end, " + (now - first) + " ms");
}

// Returns app version name String
public static String getVersionName(Context context) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
return pi.versionName == null ? "" : pi.versionName;
} catch (PackageManager.NameNotFoundException e) {
return "";
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* adapted from existing ImageGetter code in NoteCommentFragment
*/
public class WPImageGetter implements Html.ImageGetter {
private WeakReference<TextView> mWeakView;
private int mMaxSize;
private final WeakReference<TextView> mWeakView;
private final int mMaxSize;
private ImageLoader mImageLoader;
private Drawable mLoadingDrawable;
private Drawable mFailedDrawable;
Expand All @@ -43,18 +43,6 @@ public WPImageGetter(TextView view, int maxSize, ImageLoader imageLoader, Drawab
mFailedDrawable = failedDrawable;
}

public void setImageLoader(ImageLoader imageLoader) {
mImageLoader = imageLoader;
}

public void setLoadingDrawable(Drawable loadingDrawable) {
mLoadingDrawable = loadingDrawable;
}

public void setFailedDrawable(Drawable failedDrawable) {
mFailedDrawable = failedDrawable;
}

private TextView getView() {
return mWeakView.get();
}
Expand All @@ -80,9 +68,6 @@ public Drawable getDrawable(String source) {
source = PhotonUtils.getPhotonImageUrl(source, mMaxSize, 0);
}

TextView view = getView();
// Drawable loading = view.getContext().getResources().getDrawable(R.drawable.remote_image); FIXME: here
// Drawable failed = view.getContext().getResources().getDrawable(R.drawable.remote_failed);
final RemoteDrawable remote = new RemoteDrawable(mLoadingDrawable, mFailedDrawable);

mImageLoader.get(source, new ImageLoader.ImageListener() {
Expand All @@ -97,43 +82,40 @@ public void onErrorResponse(VolleyError error) {

@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
if (response.getBitmap() != null) {
// make sure view is still valid
TextView view = getView();
if (view == null) {
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
return;
}

Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
final int oldHeight = remote.getBounds().height();
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
maxWidth = mMaxSize;
}
remote.setRemoteDrawable(drawable, maxWidth);

// image is from cache? don't need to modify view height
if (isImmediate) {
return;
}

int newHeight = remote.getBounds().height();
view.invalidate();
// For ICS
view.setHeight(view.getHeight() + newHeight - oldHeight);
// Pre ICS
view.setEllipsize(null);
if (response.getBitmap() == null) {
AppLog.w(T.UTILS, "WPImageGetter null bitmap");
}

TextView view = getView();
if (view == null) {
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
return;
}

int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
maxWidth = mMaxSize;
}

Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
remote.setRemoteDrawable(drawable, maxWidth);

// force textView to resize correctly if image isn't cached by resetting the content
// to itself - this way the textView will use the cached image, and resizing to
// accommodate the image isn't necessary
if (!isImmediate) {
view.setText(view.getText());
}
}
});

return remote;
}

private static class RemoteDrawable extends BitmapDrawable {
protected Drawable mRemoteDrawable;
protected Drawable mLoadingDrawable;
protected Drawable mFailedDrawable;
Drawable mRemoteDrawable;
final Drawable mLoadingDrawable;
final Drawable mFailedDrawable;
private boolean mDidFail = false;

public RemoteDrawable(Drawable loadingDrawable, Drawable failedDrawable) {
Expand All @@ -158,11 +140,6 @@ public void setBounds(int x, int y, int width, int height) {
}
}

public void setRemoteDrawable(Drawable remote) {
mRemoteDrawable = remote;
setBounds(0, 0, mRemoteDrawable.getIntrinsicWidth(), mRemoteDrawable.getIntrinsicHeight());
}

public void setRemoteDrawable(Drawable remote, int maxWidth) {
// null sentinel for now
if (remote == null) {
Expand Down
Loading

0 comments on commit 5026c92

Please sign in to comment.