handyface

Untitled

Nov 2nd, 2012
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.90 KB | None | 0 0
  1. import java.util.concurrent.ExecutorService;
  2.  
  3. import org.apache.cordova.CordovaWebView;
  4. import org.apache.cordova.api.CordovaInterface;
  5. import org.apache.cordova.api.CordovaPlugin;
  6.  
  7. import android.app.Activity;
  8. import android.content.Context;
  9. import android.content.Intent;
  10. import android.content.res.Resources;
  11. import android.os.Build;
  12. import android.os.Bundle;
  13. import android.util.TypedValue;
  14. import android.view.View;
  15. import android.widget.RelativeLayout;
  16. import android.widget.Toast;
  17. import static com.nineoldandroids.view.ViewPropertyAnimator.animate;
  18.  
  19. public class EnkhuizenActivity extends Activity implements CordovaInterface  {
  20.  
  21.     boolean menuOn = false;
  22.     CordovaWebView menuView;
  23.     CordovaWebView mainView;
  24.     EnkAppInterface enkAppInterface = new EnkAppInterface(this);
  25.     RelativeLayout layout;
  26.     float px;
  27.    
  28.     @Override
  29.     public void onCreate(Bundle savedInstanceState) {  
  30.         super.onCreate(savedInstanceState);
  31.        
  32.         Resources r = getResources();
  33.         px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, r.getDisplayMetrics());
  34.         setContentView(R.layout.main);
  35.  
  36.         menuView = (CordovaWebView) findViewById(R.id.menu_view);
  37.         mainView = (CordovaWebView) findViewById(R.id.main_view);
  38.        
  39.         menuView.getSettings().setJavaScriptEnabled(true);
  40.         mainView.getSettings().setJavaScriptEnabled(true);
  41.  
  42.         menuView.addJavascriptInterface(enkAppInterface, "mobileFunction");
  43.         mainView.addJavascriptInterface(enkAppInterface, "mobileFunction");
  44.  
  45.         menuView.loadUrl("file:///android_asset/www/menu.html");
  46.         mainView.loadUrl("file:///android_asset/www/main.html");
  47.        
  48.         if(!(Build.VERSION.SDK_INT >= 11)) {
  49.             menuView.setVisibility(View.INVISIBLE);
  50.         }
  51.     }
  52.    
  53.     @Override
  54.     public void onBackPressed() {
  55.         if (menuOn) {
  56.             menuOut();         
  57.         } else {
  58.             mainView.loadUrl("javascript:backButtonHandler()");
  59.         }
  60.     }
  61.    
  62.     @Override
  63.     public void onDestroy()
  64.     {
  65.         super.onDestroy();
  66.         if (mainView.pluginManager != null) {
  67.             mainView.pluginManager.onDestroy();
  68.         }
  69.     }
  70.     public void bindBackButton(boolean override) {
  71.         // TODO Auto-generated method stub
  72.  
  73.     }
  74.  
  75.     public boolean isBackButtonBound() {
  76.         // TODO Auto-generated method stub
  77.         return false;
  78.     }
  79.  
  80.     public Activity getActivity() {
  81.         return this;
  82.     }
  83.  
  84.     public void cancelLoadUrl() {
  85.         // TODO Auto-generated method stub
  86.  
  87.     }
  88.  
  89.     public Boolean doMenu(String id, Object data) {
  90.         // TODO Auto-generated method stub
  91.         return null;
  92.     }
  93.     public Object onMessage(String id, Object data) {
  94.         // TODO Auto-generated method stub
  95.         return null;
  96.     }
  97.  
  98.     public Context getContext() {
  99.         return this;
  100.     }
  101.    
  102.     public void menuOut ()
  103.     {
  104.         runOnUiThread(new Runnable() {
  105.             public void run() {
  106.                
  107.                 if(Build.VERSION.SDK_INT >= 11)
  108.                 {
  109.                     animate(mainView).translationX(0);
  110.  
  111.                 } else {
  112.                     RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mainView.getLayoutParams();
  113.                     params.setMargins(0, 0, 0, 0); //substitute parameters for left, top, right, bottom
  114.                     mainView.setLayoutParams(params);
  115.                     menuView.setVisibility(View.INVISIBLE);                
  116.                 }
  117.                 layout.postInvalidate();
  118.                 menuOn = false;
  119.             }
  120.         });
  121.        
  122.     }
  123.     public void menuIn ()
  124.     {
  125.         runOnUiThread(new Runnable() {
  126.             public void run() {
  127.                
  128.                 if(Build.VERSION.SDK_INT >= 11)
  129.                 {
  130.                     animate(mainView).translationX(px);
  131.  
  132.                 } else {
  133.                     menuView.setVisibility(View.VISIBLE);
  134.                     RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mainView.getLayoutParams();
  135.                     params.setMargins((int)px, 0, 0, 0); //substitute parameters for left, top, right, bottom
  136.                     mainView.setLayoutParams(params);
  137.                 }
  138.                 layout.postInvalidate();
  139.                 menuOn = true;
  140.             }
  141.         });
  142.        
  143.     }
  144.  
  145.     public class EnkAppInterface {
  146.         Context mContext;
  147.         EnkAppInterface(Context c) {
  148.             mContext = c;
  149.         }
  150.        
  151.         public void backButton()
  152.         {
  153.             onBackPressed();
  154.         }
  155.        
  156.         public void exitApp()
  157.         {
  158.             moveTaskToBack(true);
  159.         }
  160.        
  161.         public void Toast(String text)
  162.         {
  163.             Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
  164.         }
  165.        
  166.         public void homePage() {
  167.             menuView.loadUrl("javascript:homePage();");        
  168.         }
  169.        
  170.         public void menu(String showOrHide){
  171.             if ((menuOn && showOrHide.equals("toggle")) || (showOrHide.equals("false") && menuOn)){
  172.                 menuOut();
  173.             } else  if ((!menuOn && showOrHide.equals("toggle")) || (showOrHide.equals("true") && !menuOn)){
  174.                 menuIn();
  175.             }
  176.         }  
  177.  
  178.         public void changePage(final String pageName){
  179.             menu("false");
  180.             runOnUiThread(new Runnable() {
  181.                 public void run() {
  182.                     mainView.loadUrl("javascript:addPage('"+pageName+"',true)");
  183.                 }
  184.             });
  185.            
  186.         }
  187.  
  188.     }
  189.     public ExecutorService getThreadPool() {
  190.         // TODO Auto-generated method stub
  191.         return null;
  192.     }
  193.  
  194.     public void setActivityResultCallback(CordovaPlugin arg0) {
  195.         // TODO Auto-generated method stub
  196.        
  197.     }
  198.  
  199.     public void startActivityForResult(CordovaPlugin arg0, Intent arg1, int arg2) {
  200.         // TODO Auto-generated method stub
  201.        
  202.     }
Advertisement
Add Comment
Please, Sign In to add comment