Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.gosell.ghmaster.activity;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import org.json.JSONException;
- import pl.gosell.ghmaster.R;
- import pl.gosell.ghmaster.api.ApiClient;
- import pl.gosell.ghmaster.layout.BottombarLayout;
- import pl.gosell.ghmaster.layout.ImageLayout;
- import pl.gosell.ghmaster.layout.TopbarLayout;
- import pl.gosell.ghmaster.model.ModelSklep;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.View.OnTouchListener;
- import android.webkit.JavascriptInterface;
- import android.webkit.WebChromeClient;
- import android.webkit.WebSettings;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import android.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.annotation.SuppressLint;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Bitmap;
- import com.android.lifter.activity.ActivityBase;
- import com.android.lifter.async.AsyncTask;
- import com.android.lifter.async.AsyncTask.OnTaskListener;
- import com.android.lifter.logging.Loger;
- public class ActMapa extends ActivityBase
- {
- private TopbarLayout llTop = null;
- private BottombarLayout llBottom = null;
- private Button btParter = null;
- private Button btPietro1 = null;
- private Button btPietro2 = null;
- private WebView wvMapa = null;
- private AsyncTask.OnTaskListener taskListener = new AsyncTask.OnTaskListener()
- {
- @Override
- public void onBefore()
- {
- }
- @Override
- public void onThread()
- {
- ApiClient apiClient = new ApiClient();
- String apiTxt = "";
- try
- {
- apiTxt = apiClient.mapFloorHtml(1);
- Log.d("mapa", apiTxt);
- taskCtrl.result(0, apiTxt);
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- catch (JSONException e)
- {
- e.printStackTrace();
- }
- }
- @Override
- public void onFinish()
- {
- }
- @Override
- public void onResult(int iWhat, Object obResult)
- {
- //wvMapa.loadData((String) obResult, "text/html; charset=UTF-8", null);
- String data =
- "<script type=\"text/javascript\"> " +
- "function openPopup(url) { " +
- "JavaInf.receiveValueFromJs(url);"+
- " return false; " +
- "} " +
- "</script>" +
- "<img src=\"http://www.centrumetc.pl/uploads/floor/1282711124etc_swarzedz_hala1_parter.gif\" href=\"\" usemap=\"#map\" />" +
- "<map name=\"map\">" +
- "<area shape=\"poly\" coords=\"695, 305, 695, 348, 663, 348, 663, 305\" alt=\"#1\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\" />" +
- "<area shape=\"poly\" coords=\"685, 276, 685, 307, 648, 307, 648, 290, 672, 290, 672, 275\" alt=\"#2\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"684, 261, 684, 276, 663, 276, 663, 252, 673, 252, 673, 261\" alt=\"#3\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"662, 253, 676, 253, 676, 260, 686, 260, 686, 242, 660, 242\" alt=\"#4\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"592, 236, 662, 236, 662, 276, 670, 276, 670, 294, 622, 294, 622, 273, 593, 273\" alt=\"#3\" href=\"Sklep1\"onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"546, 238, 593, 238, 593, 274, 543, 274\" alt=\"#4\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"517, 239, 517, 276, 545, 276, 545, 238\" alt=\"#5\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"417, 343, 484, 343, 487, 354, 495, 360, 505, 362, 520, 359, 525, 351, 528, 345, 664, 345, 664, 305, 648, 305, 648, 292, 622, 292, 622, 274, 357, 274, 357, 326, 371, 326, 371, 311, 383, 311, 383, 317, 417, 317\" onclick=\"return openPopup('Strona');\"/> " +
- "<area shape=\"poly\" coords=\"383, 318, 416, 318, 416, 376, 382, 376\" alt=\"#6\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"358, 326, 371, 326, 371, 313, 383, 313, 383, 376, 342, 376, 342, 344, 355, 344\" alt=\"#7\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"292, 344, 357, 344, 357, 275, 291, 275\" alt=\"#8\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"186, 341, 291, 341, 291, 275, 226, 275, 226, 298, 216, 298, 216, 320, 188, 320\" alt=\"#9\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"62, 378, 80, 378, 95, 363, 95, 316, 62, 316\" alt=\"#10\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"40, 379, 61, 379, 61, 319, 40, 319\" alt=\"#11\" href=\"Sklep1\" onclick=\"return openPopup('Strona');\"/>" +
- "<area shape=\"poly\" coords=\"17, 318, 17, 378, 40, 378, 40, 319\" alt=\"#12\" href=\"Sklep1\" onclick=\"return openPopup('Strona');\"/>" +
- "<area shape=\"poly\" coords=\"93, 303, 20, 306, 20, 319, 92, 319\" alt=\"#13\" href=\"Sklep1\" onclick=\"return openPopup('Strona');\"/>" +
- "<area shape=\"poly\" coords=\"90, 276, 90, 346, 128, 346, 137, 357, 146, 362, 156, 362, 166, 357, 170, 351, 172, 344, 186, 344, 186, 319, 216, 319, 216, 298, 227, 298, 227, 275\" alt=\"#22\" onclick=\"return openPopup(this.alt);\"/> " +
- "<area shape=\"poly\" coords=\"93, 137, 93, 276, 169, 276, 169, 135\" alt=\"#14\" href=\"Sklep1\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"684, 208, 520, 208, 520, 240, 688, 240\" alt=\"#15\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"622, 204, 578, 204, 578, 161, 614, 161, 614, 196, 620, 196\" alt=\"#16\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"660, 207, 621, 207, 621, 197, 615, 197, 615, 134, 649, 134, 649, 154, 665, 154\" alt=\"#17\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"683, 174, 683, 210, 663, 210, 663, 175\" alt=\"#18\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"686, 134, 686, 173, 664, 173, 664, 152, 651, 152, 651, 136\" alt=\"#19\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"591, 47, 686, 47, 686, 135, 591, 135\" alt=\"#20\" onclick=\"return openPopup(this.alt);\"/>" +
- "<area shape=\"poly\" coords=\"96, 45, 592, 45, 592, 136, 615, 136, 615, 162, 578, 162, 578, 210, 521, 210, 521, 275, 169, 275, 169, 136, 93, 136\" alt=\"#21\" onclick=\"return openPopup(this.alt);\"/>" +
- "</map>" ;
- wvMapa.loadData(data , "text/html; charset=UTF-8", null);
- }
- @Override
- public void onInterrupted()
- {
- }
- };
- private AsyncTask taskCtrl = new AsyncTask(taskListener);
- @Override
- protected void onRequestFeature()
- {
- removeTitle();
- orientationPortrait();
- }
- @Override
- protected int onActivityContentView()
- {
- return R.layout.act_mapa;
- }
- @SuppressLint("JavascriptInterface")
- @Override
- protected void onActivityCreate()
- {
- llTop = (TopbarLayout) findViewById(R.id.tl_top);
- llBottom = (BottombarLayout) findViewById(R.id.bl_bottom);
- btParter = super.widgetButton(R.id.bt_parter);
- btPietro1 = super.widgetButton(R.id.bt_pietro_1);
- btPietro2 = super.widgetButton(R.id.bt_pietro_2);
- wvMapa = super.widgetWebView(R.id.wv_mapa);
- WebSettings webSettings = wvMapa.getSettings();
- webSettings.setJavaScriptEnabled(true);
- webSettings.setBuiltInZoomControls(false);
- wvMapa.requestFocusFromTouch();
- wvMapa.requestFocus(View.FOCUS_DOWN);
- wvMapa.addJavascriptInterface(new JavaScriptInterface(this), "JavaInf");
- wvMapa.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
- llTop.setTytul(getResources().getString(R.string.mapa));
- llTop.setWsteczVisible(false);
- llTop.setSzukajVisible(false);
- llTop.setSpolecznoscVisible(true);
- btParter.setPressed(true);
- taskCtrl.start();
- }
- @Override
- protected void onActivityData(Intent inIntent)
- {
- }
- @Override
- protected void onActivityEvents()
- {
- btParter.setOnTouchListener(new OnTouchListener()
- {
- @Override
- public boolean onTouch(View arg0, MotionEvent arg1)
- {
- btParter.setPressed(true);
- btPietro1.setPressed(false);
- btPietro2.setPressed(false);
- return true;
- }
- });
- btPietro1.setOnTouchListener(new OnTouchListener()
- {
- @Override
- public boolean onTouch(View arg0, MotionEvent arg1)
- {
- btParter.setPressed(false);
- btPietro1.setPressed(true);
- btPietro2.setPressed(false);
- return true;
- }
- });
- btPietro2.setOnTouchListener(new OnTouchListener()
- {
- @Override
- public boolean onTouch(View arg0, MotionEvent arg1)
- {
- btParter.setPressed(false);
- btPietro1.setPressed(false);
- btPietro2.setPressed(true);
- return true;
- }
- });
- wvMapa.setWebViewClient(new WebViewClient()
- {
- @Override
- public void onPageStarted(WebView view, String url, Bitmap favicon)
- {
- Loger.d("page start..." + url);
- }
- @Override
- public void onPageFinished(WebView view, String url)
- {
- Loger.d("page finish..." + url);
- }
- @Override
- public void onLoadResource(WebView view, String url)
- {
- Loger.d("load resource..." + url);
- }
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url)
- {
- return true;
- }
- });
- }
- @Override
- protected void onActivityResume()
- {
- }
- @Override
- protected void onActivityOptionsMenu(Menu menu)
- {
- }
- @Override
- protected void onActivityOptionsItemSelected(Menu menu)
- {
- }
- @Override
- protected void onActivityPause()
- {
- }
- @Override
- protected void onActivityDestroy()
- {
- }
- @Override
- protected boolean onActivityBackPressed()
- {
- return false;
- }
- }
- class JavaScriptInterface
- {
- private Context mContext;
- private static String shopId ="";
- private static ModelSklep shop = null;
- private LinearLayout shopBar = null;
- private LinearLayout llBtn = null;
- private ImageLayout logo = null;
- private TextView nazwa = null;
- private Button btnSchowaj = null;
- private OnTaskListener getShop = new OnTaskListener() {
- private static final int RES_OK = 0;
- private static final int RES_EMPTY = 1;
- private static final int RES_ERROR_URL = -1;
- private static final int RES_ERROR_IO = -2;
- private static final int RES_ERROR_JSON = -3;
- @Override
- public void onThread()
- {
- ApiClient client = new ApiClient();
- if(shopId.length() > 0)
- {
- try
- {
- shop = client.getSklep(shopId);
- if(shop != null)
- {
- getShopCtrl.result(RES_OK, shop);
- }
- else
- {
- getShopCtrl.result(RES_EMPTY, shop);
- }
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- getShopCtrl.result(RES_ERROR_URL, null);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- getShopCtrl.result(RES_ERROR_IO, null);
- }
- catch (JSONException e)
- {
- e.printStackTrace();
- getShopCtrl.result(RES_ERROR_JSON, null);
- }
- }
- }
- @Override
- public void onResult(int iWhat, Object obResult)
- {
- if(iWhat == RES_OK)
- {
- if(((ModelSklep)obResult).logoUrl.length() > 0)
- {
- logo.imageFromWeb(((ModelSklep)obResult).logoUrl);
- }
- else
- {
- logo.imageFromResource(R.drawable.ico_aplikacja);
- }
- nazwa.setText(((ModelSklep)obResult).nazwaPelna);
- }
- else
- {
- logo.imageFromResource(R.drawable.ico_aplikacja);
- nazwa.setText(mContext.getResources().getString(R.string.noShop));
- }
- }
- @Override
- public void onInterrupted()
- {
- }
- @Override
- public void onFinish()
- {
- }
- @Override
- public void onBefore()
- {
- if(shopBar.getVisibility() == View.GONE)
- {
- ((Activity) mContext).runOnUiThread(new Runnable()
- {
- @Override
- public void run()
- {
- shopBar.setVisibility(View.VISIBLE);
- }
- });
- }
- }
- };
- private AsyncTask getShopCtrl = new AsyncTask(getShop);
- public JavaScriptInterface(Context c)
- {
- mContext = c;
- logo = (ImageLayout) ((Activity) c).findViewById(R.id.logo);
- nazwa = (TextView) ((Activity) c).findViewById(R.id.shopTitle);
- shopBar = (LinearLayout) ((Activity) c).findViewById(R.id.shop_bar);
- btnSchowaj = ((ActivityBase) c).widgetButton(R.id.schowaj);
- btnSchowaj.setOnTouchListener(new OnTouchListener()
- {
- @Override
- public boolean onTouch(View v, MotionEvent event)
- {
- if(event.getAction() == MotionEvent.ACTION_UP)
- {
- shopBar.setVisibility(View.GONE);
- nazwa.setText("");
- }
- return false;
- }
- });
- }
- @JavascriptInterface
- public void receiveValueFromJs(String str)
- {
- shopId = "";
- for(int i = 1 ; i < str.length() ; i++)
- {
- shopId += str.charAt(i);
- }
- getShopCtrl.start();
- //Toast.makeText(mContext, "Value from JS: " + shopId,Toast.LENGTH_SHORT).show();
- }
- public static String getId()
- {
- return shopId;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement