Commit 3855619c by Lee Munkyeong

offline対応。

parent cde1494f
......@@ -11,6 +11,8 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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.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. -->
......
......@@ -14,7 +14,11 @@ import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
......@@ -132,6 +136,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isNormalSize()) {
setPortraitIfNormal();
......@@ -372,19 +377,34 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
Toast.LENGTH_LONG).show();
}
});
// ブロードキャストレシーバーの追加
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
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);
tempIntent.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
tempIntent.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(receiver, tempIntent);
mChatWebView.setWebViewClient(new WebViewClient() {
......@@ -994,8 +1014,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}
@JavascriptInterface
public boolean addFavoriteUser(String shopMemberId) throws NetworkDisconnectedException, AcmsException {
public boolean addFavoriteUser(String shopMemberId) throws AcmsException {
Integer favoriteCount = communicationLogic.getFavoriteCount();
if (favoriteCount >= ABookCommConstants.SIZE.MAX_FAVORITE_COUNT ) {
mChatWebView.post(new Runnable() {
......@@ -1006,8 +1025,37 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
});
return false;
} else {
boolean result = insertFavoriteUser(shopMemberId);
if (!result) { return false; }
boolean result = false;
try {
result = insertFavoriteUser(shopMemberId);
if (!result) { return false; }
mChatWebView.post(new Runnable() {
@Override
public void run() {
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
public boolean removeFavoriteUser(String shopMemberId) throws AcmsException {
try {
boolean result = deleteFavoriteUser(shopMemberId);
if (!result) {
return false;
}
mChatWebView.post(new Runnable() {
@Override
public void run() {
......@@ -1015,24 +1063,19 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}
});
return true;
}
}
@JavascriptInterface
public void removeFavoriteUser(String shopMemberId) throws NetworkDisconnectedException, AcmsException {
boolean result = deleteFavoriteUser(shopMemberId);
if (result) {
} catch (NetworkDisconnectedException e) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.refreshContactScreen();");
mChatWebView.loadUrl("javascript:alert('接続しているネットワークがありません。');");
}
});
}
return false;
}
@JavascriptInterface
public boolean addFavoriteGroup(String groupId) throws NetworkDisconnectedException, AcmsException {
public boolean addFavoriteGroup(String groupId) throws AcmsException {
Integer favoriteCount = communicationLogic.getFavoriteCount();
if (favoriteCount >= ABookCommConstants.SIZE.MAX_FAVORITE_COUNT) {
......@@ -1044,8 +1087,12 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
});
return false;
} else {
boolean result = insertFavoriteGroup(groupId);
if (result) {
boolean result = false;
try {
result = insertFavoriteGroup(groupId);
if (!result) {
return false;
}
mChatWebView.post(new Runnable() {
@Override
public void run() {
......@@ -1053,22 +1100,43 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}
});
return true;
} catch (NetworkDisconnectedException e) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:alert('接続しているネットワークがありません。');");
}
});
}
return false;
}
return false;
}
@JavascriptInterface
public void removeFavoriteGroup(String groupId) throws NetworkDisconnectedException, AcmsException {
boolean result = deleteFavoriteGroup(groupId);
if (result) {
public boolean removeFavoriteGroup(String groupId) throws AcmsException {
boolean result = false;
try {
result = deleteFavoriteGroup(groupId);
if (!result) {
return false;
}
mChatWebView.post(new Runnable() {
@Override
public void run() {
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
......
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