Created
February 10, 2019 08:58
-
-
Save kjsman/97affa6fd22661e76ada05a60fb107ea to your computer and use it in GitHub Desktop.
'그것이 알고싶다'에 소개된 '그' 앱
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
package com.metoothenext; | |
import android.app.Activity; | |
import android.app.AlertDialog; | |
import android.app.ProgressDialog; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.Intent; | |
import android.content.IntentSender.SendIntentException; | |
import android.content.pm.PackageInfo; | |
import android.content.pm.PackageManager.NameNotFoundException; | |
import android.database.Cursor; | |
import android.graphics.Bitmap; | |
import android.graphics.Bitmap.CompressFormat; | |
import android.graphics.BitmapFactory; | |
import android.graphics.Matrix; | |
import android.location.Location; | |
import android.location.LocationListener; | |
import android.location.LocationManager; | |
import android.media.ExifInterface; | |
import android.net.Uri; | |
import android.os.AsyncTask; | |
import android.os.Build.VERSION; | |
import android.os.Bundle; | |
import android.os.Environment; | |
import android.os.Handler; | |
import android.os.Message; | |
import android.os.Process; | |
import android.os.StrictMode; | |
import android.os.StrictMode.ThreadPolicy; | |
import android.provider.MediaStore.Images.Media; | |
import android.support.annotation.NonNull; | |
import android.support.annotation.Nullable; | |
import android.support.v4.content.FileProvider; | |
import android.text.TextUtils; | |
import android.util.Base64; | |
import android.util.Log; | |
import android.view.KeyEvent; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.webkit.GeolocationPermissions.Callback; | |
import android.webkit.JavascriptInterface; | |
import android.webkit.JsResult; | |
import android.webkit.ValueCallback; | |
import android.webkit.WebChromeClient; | |
import android.webkit.WebChromeClient.FileChooserParams; | |
import android.webkit.WebSettings; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
import android.widget.FrameLayout; | |
import android.widget.ImageView; | |
import android.widget.Toast; | |
import com.google.android.gms.common.ConnectionResult; | |
import com.google.android.gms.common.api.GoogleApiClient; | |
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; | |
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; | |
import com.google.android.gms.common.api.PendingResult; | |
import com.google.android.gms.common.api.ResultCallback; | |
import com.google.android.gms.common.api.Status; | |
import com.google.android.gms.location.LocationRequest; | |
import com.google.android.gms.location.LocationServices; | |
import com.google.android.gms.location.LocationSettingsRequest.Builder; | |
import com.google.android.gms.location.LocationSettingsResult; | |
import com.metoothenext.common.PreferenceWrapper; | |
import com.metoothenext.common.Utility; | |
import com.metoothenext.common.configData; | |
import java.io.BufferedReader; | |
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.UnsupportedEncodingException; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import java.util.Date; | |
import me.leolin.shortcutbadger.ShortcutBadger; | |
import org.apache.http.NameValuePair; | |
import org.apache.http.client.ClientProtocolException; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.entity.UrlEncodedFormEntity; | |
import org.apache.http.client.methods.HttpPost; | |
import org.apache.http.impl.client.DefaultHttpClient; | |
import org.apache.http.message.BasicNameValuePair; | |
import org.apache.http.util.EntityUtils; | |
public class MainActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener { | |
private static final int INPUT_FILE_REQUEST_CODE = 1; | |
public static final int REQUEST_LOCATION = 1; | |
private static final String TYPE_IMAGE = "image/*"; | |
private static final int ZBAR_SCANNER_REQUEST = 0; | |
public static String loading_text = ""; | |
private final int CAMERA_CODE = 1111; | |
private final int GALLERY_CODE = 1112; | |
private long backKeyPressedTime = 0; | |
private long backPressedTime = 0; | |
private String currentPhotoPath; | |
public String default_upload_url = ""; | |
public String default_url = ""; | |
public String default_url_final = ""; | |
public boolean disable_back_event = false; | |
GoogleApiClient googleApiClient; | |
private final Handler handler = new Handler(); | |
LocationManager locationManager; | |
LocationRequest locationRequest; | |
Builder locationSettingsRequest; | |
private String mCameraPhotoPath; | |
private Context mContext = null; | |
AlertDialog.Builder mDialog; | |
private ValueCallback<Uri[]> mFilePathCallback; | |
String mImageCaptureName; | |
private ProgressDialog mProgressDialog = null; | |
private ValueCallback<Uri> mUploadMessage; | |
String marketVersion; | |
public String my_location_lat = ""; | |
public String my_location_lng = ""; | |
WebView newWebView = null; | |
PendingResult<LocationSettingsResult> pendingResult; | |
private Uri photoUri; | |
String verSion; | |
AlertDialog version_alert = null; | |
private WebView xWalkView; | |
/* renamed from: com.metoothenext.MainActivity$1 */ | |
class C01811 implements OnClickListener { | |
C01811() { | |
} | |
public void onClick(View v) { | |
MainActivity.this.xWalkView.goBack(); | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$2 */ | |
class C01822 implements OnClickListener { | |
C01822() { | |
} | |
public void onClick(View v) { | |
MainActivity.this.xWalkView.goForward(); | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$3 */ | |
class C01833 implements OnClickListener { | |
C01833() { | |
} | |
public void onClick(View v) { | |
if (MainActivity.this.newWebView != null) { | |
FrameLayout main = (FrameLayout) MainActivity.this.findViewById(C0201R.id.main); | |
MainActivity.this.newWebView.setVisibility(8); | |
main.removeView(MainActivity.this.newWebView); | |
MainActivity.this.xWalkView.setVisibility(0); | |
} | |
try { | |
String[] nfo = (MainActivity.getHtml(MainActivity.this.default_url + "&token=" + configData.getRegistrationId(MainActivity.this.mContext)) + "|Loading..").split("[|]"); | |
MainActivity.loading_text = nfo[1] + "&"; | |
MainActivity.loading_text = MainActivity.loading_text.split("&")[0]; | |
MainActivity.this.mProgressDialog.setMessage(MainActivity.loading_text); | |
MainActivity.this.mProgressDialog.show(); | |
MainActivity.this.xWalkView.loadUrl(nfo[0]); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$4 */ | |
class C01844 implements OnClickListener { | |
C01844() { | |
} | |
public void onClick(View v) { | |
MainActivity.this.xWalkView.loadUrl(MainActivity.this.xWalkView.getUrl().replaceAll("rdrfrmapp", "nouse")); | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$5 */ | |
class C01855 implements OnClickListener { | |
C01855() { | |
} | |
public void onClick(View v) { | |
MainActivity.this.startActivity(new Intent(MainActivity.this.mContext, settingActivity.class)); | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$6 */ | |
class C01866 implements OnClickListener { | |
C01866() { | |
} | |
public void onClick(View v) { | |
if (MainActivity.this.newWebView != null) { | |
FrameLayout main = (FrameLayout) MainActivity.this.findViewById(C0201R.id.main); | |
MainActivity.this.newWebView.setVisibility(8); | |
main.removeView(MainActivity.this.newWebView); | |
MainActivity.this.xWalkView.setVisibility(0); | |
} | |
try { | |
MainActivity.this.xWalkView.loadUrl((MainActivity.getHtml(MainActivity.this.default_url + "&token=" + configData.getRegistrationId(MainActivity.this.mContext)) + "|Loading..").split("[|]")[0].replaceAll("/index.php", "/bbs/logout.php")); | |
configData.setUserAccounts(MainActivity.this.mContext, ""); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$7 */ | |
class C01877 implements OnClickListener { | |
C01877() { | |
} | |
public void onClick(View v) { | |
try { | |
String[] nfo = (MainActivity.getHtml(MainActivity.this.default_url + "&rdrfrmapp=memo&token=" + configData.getRegistrationId(MainActivity.this.mContext)) + "|Loading..").split("[|]"); | |
MainActivity.loading_text = nfo[1] + "&"; | |
MainActivity.loading_text = MainActivity.loading_text.split("&")[0]; | |
MainActivity.this.mProgressDialog.setMessage(MainActivity.loading_text); | |
MainActivity.this.mProgressDialog.show(); | |
MainActivity.this.xWalkView.loadUrl(nfo[0]); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$8 */ | |
class C01898 implements OnClickListener { | |
/* renamed from: com.metoothenext.MainActivity$8$1 */ | |
class C01881 implements DialogInterface.OnClickListener { | |
C01881() { | |
} | |
public void onClick(DialogInterface dialog, int which) { | |
switch (which) { | |
case -1: | |
Process.killProcess(Process.myPid()); | |
MainActivity.this.finish(); | |
return; | |
default: | |
return; | |
} | |
} | |
} | |
C01898() { | |
} | |
public void onClick(View v) { | |
DialogInterface.OnClickListener dialogClickListener = new C01881(); | |
new AlertDialog.Builder(MainActivity.this.mContext).setMessage("종료하시겠습니까?").setPositiveButton("네", dialogClickListener).setNegativeButton("아니오", dialogClickListener).show(); | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$9 */ | |
class C01959 extends WebChromeClient { | |
/* renamed from: com.metoothenext.MainActivity$9$1 */ | |
class C01901 extends WebChromeClient { | |
C01901() { | |
} | |
public void openFileChooser(ValueCallback<Uri> uploadMsg) { | |
MainActivity.this.mUploadMessage = uploadMsg; | |
Intent intent = new Intent("android.intent.action.GET_CONTENT"); | |
intent.addCategory("android.intent.category.OPENABLE"); | |
intent.setType(MainActivity.TYPE_IMAGE); | |
MainActivity.this.startActivityForResult(intent, 1); | |
} | |
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { | |
System.out.println("WebViewActivity 3<A<4.1, OS Version : " + VERSION.SDK_INT + "\t openFC(VCU,aT), n=2"); | |
openFileChooser(uploadMsg, acceptType, ""); | |
} | |
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) { | |
Log.d(getClass().getName(), "openFileChooser : " + acceptType + "/" + capture); | |
MainActivity.this.mUploadMessage = uploadFile; | |
imageChooser(); | |
} | |
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { | |
System.out.println("WebViewActivity A>5, OS Version : " + VERSION.SDK_INT + "\t onSFC(WV,VCUB,FCP), n=3"); | |
if (MainActivity.this.mFilePathCallback != null) { | |
MainActivity.this.mFilePathCallback.onReceiveValue(null); | |
} | |
MainActivity.this.mFilePathCallback = filePathCallback; | |
imageChooser(); | |
return true; | |
} | |
private void imageChooser() { | |
Intent takePictureIntent = new Intent("android.media.action.IMAGE_CAPTURE"); | |
if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) { | |
File file = null; | |
try { | |
file = MainActivity.this.createImageFile(); | |
takePictureIntent.putExtra("PhotoPath", MainActivity.this.mCameraPhotoPath); | |
} catch (IOException ex) { | |
Log.d(getClass().getName(), "Unable to create Image File", ex); | |
} | |
if (file != null) { | |
MainActivity.this.mCameraPhotoPath = "file:" + file.getAbsolutePath(); | |
takePictureIntent.putExtra("output", Uri.fromFile(file)); | |
} else { | |
takePictureIntent = null; | |
} | |
} | |
Intent contentSelectionIntent = new Intent("android.intent.action.GET_CONTENT"); | |
contentSelectionIntent.addCategory("android.intent.category.OPENABLE"); | |
contentSelectionIntent.setType(MainActivity.TYPE_IMAGE); | |
Intent[] intentArray = takePictureIntent != null ? new Intent[]{takePictureIntent} : new Intent[0]; | |
Intent chooserIntent = new Intent("android.intent.action.CHOOSER"); | |
chooserIntent.putExtra("android.intent.extra.INTENT", contentSelectionIntent); | |
chooserIntent.putExtra("android.intent.extra.TITLE", "Image Chooser"); | |
chooserIntent.putExtra("android.intent.extra.INITIAL_INTENTS", intentArray); | |
MainActivity.this.startActivityForResult(chooserIntent, 1); | |
} | |
public void onCloseWindow(WebView window) { | |
Log.d("check2", "CLosewindow called"); | |
FrameLayout main = (FrameLayout) MainActivity.this.findViewById(C0201R.id.main); | |
MainActivity.this.newWebView.setVisibility(8); | |
main.removeView(MainActivity.this.newWebView); | |
MainActivity.this.xWalkView.setVisibility(0); | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$9$2 */ | |
class C01912 extends WebViewClient { | |
C01912() { | |
} | |
public void onPageFinished(WebView view, String url) { | |
} | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
Log.d("NEWWIN", "URL:" + url); | |
if (url.contains("chat.image.preview.php")) { | |
MainActivity.this.newWebView.getSettings().setBuiltInZoomControls(true); | |
MainActivity.this.newWebView.getSettings().setSupportZoom(true); | |
} else { | |
MainActivity.this.newWebView.getSettings().setBuiltInZoomControls(false); | |
MainActivity.this.newWebView.getSettings().setSupportZoom(false); | |
} | |
if (url.startsWith("newwin:")) { | |
FrameLayout main = (FrameLayout) MainActivity.this.findViewById(C0201R.id.main); | |
MainActivity.this.newWebView.setVisibility(8); | |
main.removeView(MainActivity.this.newWebView); | |
MainActivity.this.xWalkView.setVisibility(0); | |
MainActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url.replaceAll("newwin:", "")))); | |
} else if (url.startsWith("tel:")) { | |
Intent call_phone = new Intent("android.intent.action.CALL"); | |
call_phone.setData(Uri.parse(url)); | |
MainActivity.this.startActivity(call_phone); | |
} else if (url.startsWith("sms:")) { | |
MainActivity.this.startActivity(new Intent("android.intent.action.SENDTO", Uri.parse(url))); | |
} else if (url.startsWith("intent:")) { | |
try { | |
Intent intent = Intent.parseUri(url, 1); | |
if (MainActivity.this.getPackageManager().getLaunchIntentForPackage(intent.getPackage()) != null) { | |
MainActivity.this.startActivity(intent); | |
} else { | |
Intent marketIntent = new Intent("android.intent.action.VIEW"); | |
marketIntent.setData(Uri.parse("market://details?id=" + intent.getPackage())); | |
MainActivity.this.startActivity(marketIntent); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} else { | |
MainActivity.this.newWebView.loadUrl(url); | |
} | |
return true; | |
} | |
} | |
C01959() { | |
} | |
public void openFileChooser(ValueCallback<Uri> uploadMsg) { | |
MainActivity.this.mUploadMessage = uploadMsg; | |
Intent intent = new Intent("android.intent.action.GET_CONTENT"); | |
intent.addCategory("android.intent.category.OPENABLE"); | |
intent.setType(MainActivity.TYPE_IMAGE); | |
MainActivity.this.startActivityForResult(intent, 1); | |
} | |
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { | |
System.out.println("WebViewActivity 3<A<4.1, OS Version : " + VERSION.SDK_INT + "\t openFC(VCU,aT), n=2"); | |
openFileChooser(uploadMsg, acceptType, ""); | |
} | |
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) { | |
Log.d(getClass().getName(), "openFileChooser : " + acceptType + "/" + capture); | |
MainActivity.this.mUploadMessage = uploadFile; | |
imageChooser(); | |
} | |
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { | |
System.out.println("WebViewActivity A>5, OS Version : " + VERSION.SDK_INT + "\t onSFC(WV,VCUB,FCP), n=3"); | |
if (MainActivity.this.mFilePathCallback != null) { | |
MainActivity.this.mFilePathCallback.onReceiveValue(null); | |
} | |
MainActivity.this.mFilePathCallback = filePathCallback; | |
imageChooser(); | |
return true; | |
} | |
private void imageChooser() { | |
Intent takePictureIntent = new Intent("android.media.action.IMAGE_CAPTURE"); | |
if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) { | |
File file = null; | |
try { | |
file = MainActivity.this.createImageFile(); | |
takePictureIntent.putExtra("PhotoPath", MainActivity.this.mCameraPhotoPath); | |
} catch (IOException ex) { | |
Log.d(getClass().getName(), "Unable to create Image File", ex); | |
} | |
if (file != null) { | |
MainActivity.this.mCameraPhotoPath = "file:" + file.getAbsolutePath(); | |
takePictureIntent.putExtra("output", Uri.fromFile(file)); | |
} else { | |
takePictureIntent = null; | |
} | |
} | |
Intent contentSelectionIntent = new Intent("android.intent.action.GET_CONTENT"); | |
contentSelectionIntent.addCategory("android.intent.category.OPENABLE"); | |
contentSelectionIntent.setType(MainActivity.TYPE_IMAGE); | |
Intent[] intentArray = takePictureIntent != null ? new Intent[]{takePictureIntent} : new Intent[0]; | |
Intent chooserIntent = new Intent("android.intent.action.CHOOSER"); | |
chooserIntent.putExtra("android.intent.extra.INTENT", contentSelectionIntent); | |
chooserIntent.putExtra("android.intent.extra.TITLE", "Image Chooser"); | |
chooserIntent.putExtra("android.intent.extra.INITIAL_INTENTS", intentArray); | |
MainActivity.this.startActivityForResult(chooserIntent, 1); | |
} | |
public void onCloseWindow(WebView window) { | |
Log.d("check", "CLosewindow called"); | |
window.setVisibility(8); | |
} | |
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) { | |
Log.d("Called", "onCreateWindow"); | |
FrameLayout main = (FrameLayout) MainActivity.this.findViewById(C0201R.id.main); | |
MainActivity.this.newWebView = new WebView(MainActivity.this.mContext); | |
main.addView(MainActivity.this.newWebView); | |
MainActivity.this.newWebView.setVisibility(0); | |
MainActivity.this.xWalkView.setVisibility(8); | |
resultMsg.obj.setWebView(MainActivity.this.newWebView); | |
resultMsg.sendToTarget(); | |
MainActivity.this.newWebView.getSettings().setSupportMultipleWindows(false); | |
MainActivity.this.newWebView.getSettings().setJavaScriptEnabled(true); | |
MainActivity.this.newWebView.getSettings().setBuiltInZoomControls(false); | |
MainActivity.this.newWebView.setWebChromeClient(new C01901()); | |
MainActivity.this.newWebView.setWebViewClient(new C01912()); | |
return true; | |
} | |
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { | |
callback.invoke(origin, true, false); | |
} | |
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { | |
new AlertDialog.Builder(MainActivity.this).setTitle("").setMessage(message).setPositiveButton(MainActivity.this.getString(C0201R.string.confirm_ok), new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int which) { | |
result.confirm(); | |
} | |
}).setCancelable(false).create().show(); | |
return true; | |
} | |
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { | |
new AlertDialog.Builder(view.getContext()).setTitle(MainActivity.this.getString(C0201R.string.confirm_caution)).setMessage(message).setPositiveButton(MainActivity.this.getString(C0201R.string.confirm_ok), new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int which) { | |
result.confirm(); | |
} | |
}).setNegativeButton(MainActivity.this.getString(C0201R.string.confirm_cancel), new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int which) { | |
result.cancel(); | |
} | |
}).create().show(); | |
return true; | |
} | |
} | |
private class AndroidBridge { | |
private AndroidBridge() { | |
} | |
@JavascriptInterface | |
public void attach_picture() { | |
MainActivity.this.selectGallery(); | |
} | |
@JavascriptInterface | |
public void attach_photo() { | |
MainActivity.this.selectPhoto(); | |
} | |
@JavascriptInterface | |
public void setBadge(final String msg) { | |
MainActivity.this.runOnUiThread(new Runnable() { | |
public void run() { | |
ShortcutBadger.applyCount(MainActivity.this.mContext, Integer.parseInt(msg)); | |
try { | |
if (GCMIntentService.redirect_url != null && !GCMIntentService.redirect_url.equals("")) { | |
if (GCMIntentService.redirect_url.equals("memo")) { | |
MainActivity.this.xWalkView.loadUrl("javascript:window.open('/bbs/memo.php');"); | |
} else { | |
MainActivity.this.xWalkView.loadUrl(GCMIntentService.redirect_url); | |
} | |
GCMIntentService.redirect_url = ""; | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
} | |
private class getMarketVersion extends AsyncTask<Void, Void, String> { | |
/* renamed from: com.metoothenext.MainActivity$getMarketVersion$1 */ | |
class C01971 implements DialogInterface.OnClickListener { | |
C01971() { | |
} | |
public void onClick(DialogInterface dialog, int id) { | |
Intent marketLaunch = new Intent("android.intent.action.VIEW"); | |
marketLaunch.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.metoothenext")); | |
MainActivity.this.startActivity(marketLaunch); | |
MainActivity.this.finish(); | |
} | |
} | |
/* renamed from: com.metoothenext.MainActivity$getMarketVersion$2 */ | |
class C01982 implements DialogInterface.OnClickListener { | |
C01982() { | |
} | |
public void onClick(DialogInterface dialog, int id) { | |
try { | |
MainActivity.this.version_alert.cancel(); | |
MainActivity.this.version_alert.dismiss(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
private getMarketVersion() { | |
} | |
protected void onPreExecute() { | |
super.onPreExecute(); | |
} | |
protected String doInBackground(Void... params) { | |
try { | |
MainActivity.this.marketVersion = MainActivity.getHtml("https://play.google.com/store/apps/details?id=com.metoothenext&hl=en").split("Current Version</div><span class=\"htlgb\"><div><span class=\"htlgb\">")[1].split("</span>")[0]; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return MainActivity.this.marketVersion; | |
} | |
protected void onPostExecute(String result) { | |
PackageInfo pi = null; | |
try { | |
pi = MainActivity.this.getPackageManager().getPackageInfo(MainActivity.this.getPackageName(), 0); | |
} catch (NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
MainActivity.this.verSion = pi.versionName; | |
MainActivity.this.marketVersion = result; | |
String selected_language = PreferenceWrapper.getPreferenceString(MainActivity.this.mContext, "language", ""); | |
String update_txt1 = ""; | |
String update_txt2 = ""; | |
String update_txt3 = ""; | |
if (selected_language.equals("") || selected_language.equals("kr")) { | |
update_txt1 = "최신버전으로 업데이트 후 사용해주세요."; | |
update_txt2 = "업데이트 바로가기"; | |
update_txt3 = "다음에 하기"; | |
} else if (selected_language.equals("us")) { | |
update_txt1 = "Please update to the latest version."; | |
update_txt2 = "Update Now"; | |
update_txt3 = "Not Now"; | |
} | |
if (!MainActivity.this.verSion.equals(MainActivity.this.marketVersion)) { | |
MainActivity.this.mDialog.setMessage(update_txt1).setCancelable(true).setNegativeButton(update_txt3, new C01982()).setPositiveButton(update_txt2, new C01971()); | |
MainActivity.this.version_alert = MainActivity.this.mDialog.create(); | |
MainActivity.this.version_alert.setTitle(""); | |
MainActivity.this.version_alert.show(); | |
} | |
super.onPostExecute(result); | |
} | |
} | |
public boolean isCameraAvailable() { | |
return getPackageManager().hasSystemFeature("android.hardware.camera"); | |
} | |
public void onBackPressed() { | |
if (System.currentTimeMillis() > this.backKeyPressedTime + 2000) { | |
this.backKeyPressedTime = System.currentTimeMillis(); | |
Toast.makeText(this.mContext, "'뒤로'버튼을 한번 더 누르시면 종료됩니다.", 0).show(); | |
} else if (System.currentTimeMillis() <= this.backKeyPressedTime + 2000) { | |
finish(); | |
} | |
} | |
public boolean dispatchKeyEvent(KeyEvent event) { | |
if (event.getKeyCode() != 4) { | |
return false; | |
} | |
WebView mXWalkView = (WebView) findViewById(C0201R.id.webView); | |
if (System.currentTimeMillis() > this.backPressedTime + 500) { | |
FrameLayout main = (FrameLayout) findViewById(C0201R.id.main); | |
if (this.xWalkView.getVisibility() != 0) { | |
try { | |
Log.d("ssssss", "close popup"); | |
this.newWebView.loadUrl("javascript:window.close();"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
this.backPressedTime = System.currentTimeMillis(); | |
} else if (mXWalkView.canGoBack()) { | |
mXWalkView.goBack(); | |
this.backPressedTime = System.currentTimeMillis(); | |
} else { | |
if (System.currentTimeMillis() > this.backKeyPressedTime + 2000) { | |
this.backKeyPressedTime = System.currentTimeMillis(); | |
Toast.makeText(this.mContext, "'뒤로'버튼을 한번 더 누르시면 종료됩니다.", 0).show(); | |
} else if (System.currentTimeMillis() <= this.backKeyPressedTime + 2000) { | |
finish(); | |
} | |
this.backPressedTime = System.currentTimeMillis(); | |
} | |
} | |
return true; | |
} | |
public static String getHtml(String url) throws IOException { | |
StrictMode.setThreadPolicy(new ThreadPolicy.Builder().permitDiskReads().permitDiskWrites().permitNetwork().build()); | |
URLConnection connection = new URL(url).openConnection(); | |
connection.setConnectTimeout(1000); | |
connection.setReadTimeout(500); | |
connection.connect(); | |
InputStream in = connection.getInputStream(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); | |
StringBuilder html = new StringBuilder(); | |
while (true) { | |
String line = reader.readLine(); | |
if (line != null) { | |
html.append(line); | |
} else { | |
in.close(); | |
return html.toString(); | |
} | |
} | |
} | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(C0201R.layout.main); | |
this.mContext = this; | |
this.mDialog = new AlertDialog.Builder(this); | |
new getMarketVersion().execute(new Void[0]); | |
getWindow().addFlags(8192); | |
this.default_url = "http://genedigm.com/product/metoo.php/?device=A"; | |
String mURL = getIntent().getStringExtra("URL"); | |
this.default_url_final = this.default_url; | |
if (!(mURL == null || mURL.equals(""))) { | |
this.default_url_final += "&check_redirect=1"; | |
GCMIntentService.redirect_url = mURL; | |
} | |
this.xWalkView = (WebView) findViewById(C0201R.id.webView); | |
this.xWalkView.getSettings().setJavaScriptEnabled(true); | |
this.mProgressDialog = new ProgressDialog(this); | |
this.mProgressDialog.setMessage(loading_text); | |
this.mProgressDialog.setIndeterminate(true); | |
this.mProgressDialog.setCanceledOnTouchOutside(false); | |
try { | |
String[] nfo = ((getHtml(this.default_url_final + "&token=" + configData.getRegistrationId(this.mContext)) + "&auto=" + configData.getUserAccounts(this.mContext)) + "|Loading..").split("[|]"); | |
loading_text = nfo[1] + "&"; | |
loading_text = loading_text.split("&")[0]; | |
this.mProgressDialog.setMessage(loading_text); | |
this.mProgressDialog.show(); | |
this.default_upload_url = nfo[0]; | |
this.xWalkView.loadUrl(nfo[0]); | |
} catch (Exception e) { | |
Toast.makeText(this.mContext, "서버에 접속할 수 없습니다", 1).show(); | |
finish(); | |
e.printStackTrace(); | |
} | |
provide_location_info(); | |
ImageView arrow_right = (ImageView) findViewById(C0201R.id.arrow_right); | |
ImageView home = (ImageView) findViewById(C0201R.id.home); | |
ImageView refresh = (ImageView) findViewById(C0201R.id.refresh); | |
ImageView setting = (ImageView) findViewById(C0201R.id.setting); | |
ImageView message = (ImageView) findViewById(C0201R.id.message); | |
ImageView logout = (ImageView) findViewById(C0201R.id.logout); | |
ImageView exit = (ImageView) findViewById(C0201R.id.exit); | |
((ImageView) findViewById(C0201R.id.arrow_left)).setOnClickListener(new C01811()); | |
arrow_right.setOnClickListener(new C01822()); | |
home.setOnClickListener(new C01833()); | |
refresh.setOnClickListener(new C01844()); | |
setting.setOnClickListener(new C01855()); | |
logout.setOnClickListener(new C01866()); | |
message.setOnClickListener(new C01877()); | |
exit.setOnClickListener(new C01898()); | |
WebSettings webSetting = this.xWalkView.getSettings(); | |
webSetting.setJavaScriptCanOpenWindowsAutomatically(true); | |
webSetting.setJavaScriptEnabled(true); | |
webSetting.setDomStorageEnabled(true); | |
webSetting.setGeolocationEnabled(true); | |
webSetting.setCacheMode(2); | |
webSetting.setBuiltInZoomControls(true); | |
webSetting.setUseWideViewPort(true); | |
webSetting.setLoadWithOverviewMode(true); | |
webSetting.setSupportMultipleWindows(true); | |
this.xWalkView.setLayerType(1, null); | |
webSetting.setAllowFileAccess(true); | |
webSetting.setJavaScriptCanOpenWindowsAutomatically(true); | |
this.xWalkView.requestFocus(); | |
if (VERSION.SDK_INT >= 19) { | |
this.xWalkView.setLayerType(2, null); | |
} else { | |
this.xWalkView.setLayerType(1, null); | |
} | |
this.xWalkView.getSettings().setBuiltInZoomControls(false); | |
this.xWalkView.requestFocusFromTouch(); | |
this.xWalkView.addJavascriptInterface(new AndroidBridge(), "android"); | |
this.xWalkView.setWebChromeClient(new C01959()); | |
this.xWalkView.setWebViewClient(new WebViewClient() { | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
if (url.startsWith("tel:")) { | |
Intent call_phone = new Intent("android.intent.action.CALL"); | |
call_phone.setData(Uri.parse(url)); | |
MainActivity.this.startActivity(call_phone); | |
return true; | |
} else if (url.startsWith("sms:")) { | |
MainActivity.this.startActivity(new Intent("android.intent.action.SENDTO", Uri.parse(url))); | |
return true; | |
} else if (url.startsWith("intent:")) { | |
try { | |
Intent intent = Intent.parseUri(url, 1); | |
if (MainActivity.this.getPackageManager().getLaunchIntentForPackage(intent.getPackage()) != null) { | |
MainActivity.this.startActivity(intent); | |
} else { | |
Intent marketIntent = new Intent("android.intent.action.VIEW"); | |
marketIntent.setData(Uri.parse("market://details?id=" + intent.getPackage())); | |
MainActivity.this.startActivity(marketIntent); | |
} | |
return true; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return true; | |
} | |
} else { | |
if (url.contains("cm=act_req_location")) { | |
MainActivity.this.provide_location_info(); | |
} | |
if (!(MainActivity.this.mProgressDialog == null || MainActivity.this.mProgressDialog.isShowing())) { | |
MainActivity.this.mProgressDialog.show(); | |
} | |
WebView vv = view; | |
String auto_login_token = configData.getUserAccounts(MainActivity.this.mContext); | |
if (url.contains("?")) { | |
url = url + "&device=A&token=" + configData.getRegistrationId(MainActivity.this.mContext); | |
if (url.contains("logout.php")) { | |
configData.setUserAccounts(MainActivity.this.mContext, ""); | |
} else { | |
url = url + "&auto=" + auto_login_token; | |
} | |
} else { | |
url = url + "?device=A&token=" + configData.getRegistrationId(MainActivity.this.mContext); | |
if (url.contains("logout.php")) { | |
configData.setUserAccounts(MainActivity.this.mContext, ""); | |
} else { | |
url = url + "&auto=" + auto_login_token; | |
} | |
} | |
url = url + "&lat=" + MainActivity.this.my_location_lat + "&lng=" + MainActivity.this.my_location_lng; | |
url = url + "&adp_lang=" + PreferenceWrapper.getPreferenceString(MainActivity.this.mContext, "language", ""); | |
Log.d("F-URL", url); | |
MainActivity.this.xWalkView.loadUrl(url); | |
if (url.contains("&clear_history=now")) { | |
MainActivity.this.xWalkView.clearHistory(); | |
} | |
if (url.contains("save=")) { | |
configData.setUserAccounts(MainActivity.this.mContext, (url.split("save=")[1] + "&").split("&")[0]); | |
} | |
return true; | |
} | |
} | |
public void onPageStarted(WebView view, String url, Bitmap favicon) { | |
super.onPageStarted(view, url, favicon); | |
if (MainActivity.this.mProgressDialog != null && !MainActivity.this.mProgressDialog.isShowing()) { | |
MainActivity.this.mProgressDialog.show(); | |
} | |
} | |
public void onPageFinished(WebView view, String url) { | |
if (MainActivity.this.mProgressDialog != null && MainActivity.this.mProgressDialog.isShowing()) { | |
MainActivity.this.mProgressDialog.dismiss(); | |
} | |
} | |
}); | |
} | |
private File createImageFile() throws IOException { | |
File dir = new File(Environment.getExternalStorageDirectory() + "/path/"); | |
if (!dir.exists()) { | |
dir.mkdirs(); | |
} | |
this.mImageCaptureName = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ".png"; | |
File storageDir = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + "/path/" + this.mImageCaptureName); | |
this.currentPhotoPath = storageDir.getAbsolutePath(); | |
return storageDir; | |
} | |
public void provide_location_info() { | |
LocationManager locationManager = (LocationManager) getSystemService("location"); | |
locationManager = (LocationManager) getSystemService("location"); | |
if (!locationManager.isProviderEnabled("gps")) { | |
mEnableGps(); | |
} | |
boolean isGPSEnabled = locationManager.isProviderEnabled("gps"); | |
boolean isNetworkEnabled = locationManager.isProviderEnabled("network"); | |
Log.d("Main", "isGPSEnabled=" + isGPSEnabled); | |
Log.d("Main", "isNetworkEnabled=" + isNetworkEnabled); | |
LocationListener locationListener = new LocationListener() { | |
public void onLocationChanged(Location location) { | |
double lat = location.getLatitude(); | |
double lng = location.getLongitude(); | |
MainActivity.this.my_location_lat = String.valueOf(lat); | |
MainActivity.this.my_location_lng = String.valueOf(lng); | |
} | |
public void onStatusChanged(String provider, int status, Bundle extras) { | |
Log.d("info", "onStatusChanged"); | |
} | |
public void onProviderEnabled(String provider) { | |
Log.d("info", "onProviderEnabled"); | |
} | |
public void onProviderDisabled(String provider) { | |
Log.d("info", "onProviderDisabled"); | |
} | |
}; | |
locationManager.requestLocationUpdates("network", 0, 0.0f, locationListener); | |
locationManager.requestLocationUpdates("gps", 0, 0.0f, locationListener); | |
} | |
public void mEnableGps() { | |
this.googleApiClient = new GoogleApiClient.Builder(this.mContext).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); | |
this.googleApiClient.connect(); | |
mLocationSetting(); | |
} | |
public void mLocationSetting() { | |
this.locationRequest = LocationRequest.create(); | |
this.locationRequest.setPriority(100); | |
this.locationSettingsRequest = new Builder().addLocationRequest(this.locationRequest); | |
mResult(); | |
} | |
public void mResult() { | |
this.pendingResult = LocationServices.SettingsApi.checkLocationSettings(this.googleApiClient, this.locationSettingsRequest.build()); | |
this.pendingResult.setResultCallback(new ResultCallback<LocationSettingsResult>() { | |
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) { | |
Status status = locationSettingsResult.getStatus(); | |
switch (status.getStatusCode()) { | |
case 6: | |
try { | |
status.startResolutionForResult(MainActivity.this, 1); | |
return; | |
} catch (SendIntentException e) { | |
return; | |
} | |
default: | |
return; | |
} | |
} | |
}); | |
} | |
private Uri getResultUri(Intent data) { | |
if (data != null && !TextUtils.isEmpty(data.getDataString())) { | |
String filePath = ""; | |
if (VERSION.SDK_INT >= 21) { | |
filePath = data.getDataString(); | |
} else { | |
filePath = "file:" + RealPathUtil.getRealPath(this, data.getData()); | |
} | |
return Uri.parse(filePath); | |
} else if (this.mCameraPhotoPath != null) { | |
return Uri.parse(this.mCameraPhotoPath); | |
} else { | |
return null; | |
} | |
} | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == 1 && resultCode == -1) { | |
try { | |
if (VERSION.SDK_INT >= 21) { | |
if (this.mFilePathCallback == null) { | |
super.onActivityResult(requestCode, resultCode, data); | |
return; | |
} | |
this.mFilePathCallback.onReceiveValue(new Uri[]{getResultUri(data)}); | |
this.mFilePathCallback = null; | |
} else if (this.mUploadMessage == null) { | |
super.onActivityResult(requestCode, resultCode, data); | |
return; | |
} else { | |
Uri result = getResultUri(data); | |
Log.d(getClass().getName(), "openFileChooser : " + result); | |
this.mUploadMessage.onReceiveValue(result); | |
this.mUploadMessage = null; | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return; | |
} | |
} | |
if (this.mFilePathCallback != null) { | |
this.mFilePathCallback.onReceiveValue(null); | |
} | |
if (this.mUploadMessage != null) { | |
this.mUploadMessage.onReceiveValue(null); | |
} | |
this.mFilePathCallback = null; | |
this.mUploadMessage = null; | |
super.onActivityResult(requestCode, resultCode, data); | |
switch (requestCode) { | |
case 1: | |
switch (resultCode) { | |
case -1: | |
case 0: | |
break; | |
default: | |
break; | |
} | |
case 1111: | |
getPictureForPhoto(); | |
break; | |
case 1112: | |
sendPicture(data.getData()); | |
break; | |
} | |
if (this.xWalkView == null) { | |
} | |
} | |
public void onConnected(@Nullable Bundle bundle) { | |
} | |
public void onConnectionSuspended(int i) { | |
} | |
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { | |
} | |
protected void onPause() { | |
super.onPause(); | |
if (this.xWalkView != null) { | |
this.xWalkView.pauseTimers(); | |
} | |
} | |
protected void onResume() { | |
super.onResume(); | |
if (this.xWalkView != null) { | |
this.xWalkView.resumeTimers(); | |
} | |
} | |
protected void onDestroy() { | |
super.onDestroy(); | |
if (this.xWalkView != null) { | |
} | |
if (this.mProgressDialog != null) { | |
this.mProgressDialog.dismiss(); | |
} | |
} | |
protected void onNewIntent(Intent intent) { | |
if (this.xWalkView == null) { | |
} | |
} | |
private void selectPhoto() { | |
if ("mounted".equals(Environment.getExternalStorageState())) { | |
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); | |
if (intent.resolveActivity(getPackageManager()) != null) { | |
File photoFile = null; | |
try { | |
photoFile = createImageFile(); | |
} catch (IOException e) { | |
} | |
if (photoFile != null) { | |
this.photoUri = FileProvider.getUriForFile(this.mContext, getPackageName(), photoFile); | |
intent.putExtra("output", this.photoUri); | |
startActivityForResult(intent, 1111); | |
} | |
} | |
} | |
} | |
private void getPictureForPhoto() { | |
int exifDegree; | |
Bitmap bitmap = BitmapFactory.decodeFile(this.currentPhotoPath); | |
ExifInterface exif = null; | |
try { | |
exif = new ExifInterface(this.currentPhotoPath); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
if (exif != null) { | |
exifDegree = exifOrientationToDegrees(exif.getAttributeInt("Orientation", 1)); | |
} else { | |
exifDegree = 0; | |
} | |
uploadPhoto(rotate(bitmap, (float) exifDegree)); | |
} | |
private void selectGallery() { | |
Intent intent = new Intent("android.intent.action.PICK"); | |
intent.setData(Media.EXTERNAL_CONTENT_URI); | |
intent.setType(TYPE_IMAGE); | |
startActivityForResult(intent, 1112); | |
} | |
private void sendPicture(Uri imgUri) { | |
String imagePath = getRealPathFromURI(imgUri); | |
ExifInterface exif = null; | |
try { | |
exif = new ExifInterface(imagePath); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
uploadPhoto(rotate(BitmapFactory.decodeFile(imagePath), (float) exifOrientationToDegrees(exif.getAttributeInt("Orientation", 1)))); | |
} | |
private int exifOrientationToDegrees(int exifOrientation) { | |
if (exifOrientation == 6) { | |
return 90; | |
} | |
if (exifOrientation == 3) { | |
return 180; | |
} | |
if (exifOrientation == 8) { | |
return 270; | |
} | |
return 0; | |
} | |
private Bitmap rotate(Bitmap src, float degree) { | |
Matrix matrix = new Matrix(); | |
matrix.postRotate(degree); | |
return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); | |
} | |
private String getRealPathFromURI(Uri contentUri) { | |
int column_index = 0; | |
Cursor cursor = getContentResolver().query(contentUri, new String[]{"_data"}, null, null, null); | |
if (cursor.moveToFirst()) { | |
column_index = cursor.getColumnIndexOrThrow("_data"); | |
} | |
return cursor.getString(column_index); | |
} | |
public void send_image_to_chat_window(String fn) { | |
} | |
private void uploadPhoto(Bitmap bitmap1) { | |
Log.e("Start", "upload bitmap"); | |
final Bitmap bitmap = resizeBitmapImage(bitmap1, 1024); | |
new Thread(new Runnable() { | |
public void run() { | |
ByteArrayOutputStream bao = new ByteArrayOutputStream(); | |
bitmap.compress(CompressFormat.JPEG, 100, bao); | |
String ba1 = Base64.encodeToString(bao.toByteArray(), 0); | |
ArrayList<NameValuePair> nameValuePairs = new ArrayList(); | |
nameValuePairs.add(new BasicNameValuePair("chat_attach_image", ba1)); | |
try { | |
HttpClient client = new DefaultHttpClient(); | |
Log.e("upload url :", MainActivity.this.default_upload_url); | |
HttpPost post = new HttpPost(MainActivity.this.default_upload_url); | |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); | |
String responseBody = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8"); | |
Log.e("RESPONSE", responseBody.toString()); | |
final String img_url = responseBody.toString(); | |
MainActivity.this.runOnUiThread(new Runnable() { | |
public void run() { | |
MainActivity.this.xWalkView.loadUrl("javascript:send_picture('" + Utility.urlEncode(img_url) + "');"); | |
} | |
}); | |
} catch (UnsupportedEncodingException e) { | |
e.printStackTrace(); | |
} catch (ClientProtocolException e2) { | |
e2.printStackTrace(); | |
} catch (IOException e3) { | |
e3.printStackTrace(); | |
} | |
} | |
}).start(); | |
} | |
public Bitmap resizeBitmapImage(Bitmap source, int maxResolution) { | |
int width = source.getWidth(); | |
int height = source.getHeight(); | |
int newWidth = width; | |
int newHeight = height; | |
if (width > height) { | |
if (maxResolution < width) { | |
newHeight = (int) (((float) height) * (((float) maxResolution) / ((float) width))); | |
newWidth = maxResolution; | |
} | |
} else if (maxResolution < height) { | |
newWidth = (int) (((float) width) * (((float) maxResolution) / ((float) height))); | |
newHeight = maxResolution; | |
} | |
return Bitmap.createScaledBitmap(source, newWidth, newHeight, true); | |
} | |
public static String getMarketVersionFast(String packageName) { | |
String mData = ""; | |
try { | |
HttpURLConnection mConnection = (HttpURLConnection) new URL("https://play.google.com/store/apps/details?id=" + packageName).openConnection(); | |
if (mConnection == null) { | |
return null; | |
} | |
String mVer; | |
mConnection.setConnectTimeout(5000); | |
mConnection.setUseCaches(false); | |
mConnection.setDoOutput(true); | |
if (mConnection.getResponseCode() == 200) { | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mConnection.getInputStream())); | |
while (true) { | |
String line = bufferedReader.readLine(); | |
if (line == null) { | |
break; | |
} | |
mData = mData + line; | |
} | |
bufferedReader.close(); | |
} | |
mConnection.disconnect(); | |
String startToken = "softwareVersion\">"; | |
String endToken = "<"; | |
int index = mData.indexOf(startToken); | |
if (index == -1) { | |
mVer = null; | |
} else { | |
mVer = mData.substring(startToken.length() + index, (startToken.length() + index) + 100); | |
mVer = mVer.substring(0, mVer.indexOf(endToken)).trim(); | |
} | |
return mVer; | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
asdf