Commit 3855619c by Lee Munkyeong

offline対応。

parent cde1494f
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_TASKS" /><!-- ActivityManager.RunningTaskInfo --> <uses-permission android:name="android.permission.GET_TASKS" /><!-- ActivityManager.RunningTaskInfo -->
<uses-permission android:name="android.permission.WAKE_LOCK" /><!-- using PowerManager WakeLocks to keep processor from sleeping or screen from dimming --> <uses-permission android:name="android.permission.WAKE_LOCK" /><!-- using PowerManager WakeLocks to keep processor from sleeping or screen from dimming -->
<uses-permission android:name="android.permission.READ_LOGS" /><!-- an application to read the low-level system log files. --> <uses-permission android:name="android.permission.READ_LOGS" /><!-- an application to read the low-level system log files. -->
......
...@@ -14,7 +14,11 @@ import android.content.SharedPreferences; ...@@ -14,7 +14,11 @@ import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
...@@ -132,6 +136,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity { ...@@ -132,6 +136,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (isNormalSize()) { if (isNormalSize()) {
setPortraitIfNormal(); setPortraitIfNormal();
...@@ -372,19 +377,34 @@ public class ChatWebviewActivity extends ParentWebViewActivity { ...@@ -372,19 +377,34 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
}); });
// ブロードキャストレシーバーの追加 // ブロードキャストレシーバーの追加
receiver = new BroadcastReceiver() { receiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) { if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
mChatWebView.loadUrl("javascript:CHAT_UI.dismissLoadingIndicator()"); mChatWebView.loadUrl("javascript:CHAT_UI.dismissLoadingIndicator()");
} }
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
isOnline = false;
mChatWebView.loadUrl("javascript:CHAT_UI.refreshForOffline();");
} else {
isOnline = true;
mChatWebView.loadUrl("javascript:CHAT_UI.refreshForOnline();");
}
}
} }
}; };
// レシーバーオブジェクトの生成 // レシーバーオブジェクトの生成
IntentFilter tempIntent = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); IntentFilter tempIntent = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
tempIntent.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
tempIntent.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(receiver, tempIntent); registerReceiver(receiver, tempIntent);
mChatWebView.setWebViewClient(new WebViewClient() { mChatWebView.setWebViewClient(new WebViewClient() {
...@@ -994,8 +1014,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity { ...@@ -994,8 +1014,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
} }
@JavascriptInterface @JavascriptInterface
public boolean addFavoriteUser(String shopMemberId) throws NetworkDisconnectedException, AcmsException { public boolean addFavoriteUser(String shopMemberId) throws AcmsException {
Integer favoriteCount = communicationLogic.getFavoriteCount(); Integer favoriteCount = communicationLogic.getFavoriteCount();
if (favoriteCount >= ABookCommConstants.SIZE.MAX_FAVORITE_COUNT ) { if (favoriteCount >= ABookCommConstants.SIZE.MAX_FAVORITE_COUNT ) {
mChatWebView.post(new Runnable() { mChatWebView.post(new Runnable() {
...@@ -1006,8 +1025,11 @@ public class ChatWebviewActivity extends ParentWebViewActivity { ...@@ -1006,8 +1025,11 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}); });
return false; return false;
} else { } else {
boolean result = insertFavoriteUser(shopMemberId); boolean result = false;
try {
result = insertFavoriteUser(shopMemberId);
if (!result) { return false; } if (!result) { return false; }
mChatWebView.post(new Runnable() { mChatWebView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -1015,24 +1037,45 @@ public class ChatWebviewActivity extends ParentWebViewActivity { ...@@ -1015,24 +1037,45 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
} }
}); });
return true; return true;
} catch (NetworkDisconnectedException e) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:alert('接続しているネットワークがありません。');");
}
});
} }
} }
return false;
}
@JavascriptInterface @JavascriptInterface
public void removeFavoriteUser(String shopMemberId) throws NetworkDisconnectedException, AcmsException { public boolean removeFavoriteUser(String shopMemberId) throws AcmsException {
try {
boolean result = deleteFavoriteUser(shopMemberId); boolean result = deleteFavoriteUser(shopMemberId);
if (result) { if (!result) {
return false;
}
mChatWebView.post(new Runnable() { mChatWebView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.refreshContactScreen();"); mChatWebView.loadUrl("javascript:CHAT_UI.refreshContactScreen();");
} }
}); });
return true;
} catch (NetworkDisconnectedException e) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:alert('接続しているネットワークがありません。');");
} }
});
}
return false;
} }
@JavascriptInterface @JavascriptInterface
public boolean addFavoriteGroup(String groupId) throws NetworkDisconnectedException, AcmsException { public boolean addFavoriteGroup(String groupId) throws AcmsException {
Integer favoriteCount = communicationLogic.getFavoriteCount(); Integer favoriteCount = communicationLogic.getFavoriteCount();
if (favoriteCount >= ABookCommConstants.SIZE.MAX_FAVORITE_COUNT) { if (favoriteCount >= ABookCommConstants.SIZE.MAX_FAVORITE_COUNT) {
...@@ -1044,8 +1087,12 @@ public class ChatWebviewActivity extends ParentWebViewActivity { ...@@ -1044,8 +1087,12 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}); });
return false; return false;
} else { } else {
boolean result = insertFavoriteGroup(groupId); boolean result = false;
if (result) { try {
result = insertFavoriteGroup(groupId);
if (!result) {
return false;
}
mChatWebView.post(new Runnable() { mChatWebView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -1053,22 +1100,43 @@ public class ChatWebviewActivity extends ParentWebViewActivity { ...@@ -1053,22 +1100,43 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
} }
}); });
return true; return true;
} catch (NetworkDisconnectedException e) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:alert('接続しているネットワークがありません。');");
}
});
} }
return false;
} }
return false;
} }
@JavascriptInterface @JavascriptInterface
public void removeFavoriteGroup(String groupId) throws NetworkDisconnectedException, AcmsException { public boolean removeFavoriteGroup(String groupId) throws AcmsException {
boolean result = deleteFavoriteGroup(groupId); boolean result = false;
if (result) { try {
result = deleteFavoriteGroup(groupId);
if (!result) {
return false;
}
mChatWebView.post(new Runnable() { mChatWebView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.refreshContactScreen();"); mChatWebView.loadUrl("javascript:CHAT_UI.refreshContactScreen();");
} }
}); });
return true;
} catch (NetworkDisconnectedException e) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:alert('接続しているネットワークがありません。');");
} }
});
}
return false;
} }
@JavascriptInterface @JavascriptInterface
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment