Lockerz app Concept

Quickly share your Android Code Snippets here...

Lockerz app Concept

Postby BLAKE.AnRKist » Tue Feb 23, 2010 1:30 pm

I don't think many of you know about Lockerz, but I thought it would be fun to create a client that grabs serverside generated HTML content and have interaction for the content of Lockerz. Tabs will probably be put to use upon nearing a 1.0 of my app.

This is only a concept, it displays the login page in a webview (looks ugly). After logging in, you get presented with a alert dialog that grabs some values from the page.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class maLocker extends Activity {
  2.  
  3.        
  4.  
  5.         final maLocker theApp = this;
  6.  
  7.        
  8.  
  9.         int a = 0;
  10.  
  11.        
  12.  
  13.         String att1 = "class";
  14.  
  15.        
  16.  
  17.         String atv1 = "ptz_value";
  18.  
  19.         String atv2 = "friends";
  20.  
  21.         String atv3 = "check-in-active";
  22.  
  23.         //String atv4 = "completed check-in-notactive";
  24.  
  25.         String ptzValue;
  26.  
  27.         String friends;
  28.  
  29.        
  30.  
  31.     //String urla = "file:///android_asset/Lockerz.htm";
  32.  
  33.     String urla = "http://www.lockerz.com";
  34.  
  35.        
  36.  
  37.    
  38.  
  39.         public class MyJavaScriptInterface
  40.  
  41.         {
  42.  
  43.                
  44.  
  45.             public void showHTML(String html) throws IOException
  46.  
  47.             {
  48.  
  49.                 String checkIn;
  50.  
  51.                 String aVal;
  52.  
  53.                 try{                   
  54.  
  55.                         HtmlCleaner parser = new HtmlCleaner();
  56.  
  57.                         TagNode node = parser.clean(html);
  58.  
  59.                
  60.  
  61.                         TagNode node1 = node.findElementByAttValue(att1, atv1, true, true);
  62.  
  63.                         TagNode node2 = node.findElementByAttValue(att1, atv2, true, true);
  64.  
  65.                         ptzValue = node1.getText().toString();
  66.  
  67.                         friends = node2.getText().toString();
  68.  
  69.                        
  70.  
  71.                         Pattern nPtt = Pattern.compile("[0-9]+");
  72.  
  73.                         Matcher m = nPtt.matcher(friends);
  74.  
  75.                         int numberFr = 0;
  76.  
  77.                         if (m.find()){
  78.  
  79.                           numberFr = Integer.parseInt(m.group(0));
  80.  
  81.                         }
  82.  
  83.                        
  84.  
  85.                         try{
  86.  
  87.                                 TagNode node3 = node.findElementByAttValue(att1, atv3, true, true);
  88.  
  89.                                 aVal = node3.getText().toString();
  90.  
  91.                                         checkIn="No!";
  92.  
  93.                                 }catch (Exception e){
  94.  
  95.                                         checkIn="Yes!";
  96.  
  97.                                 }
  98.  
  99.                        
  100.  
  101.                     new AlertDialog.Builder(theApp)
  102.  
  103.                     .setTitle("Report")
  104.  
  105.                     .setMessage("Ptz: "+ptzValue+" Friends: "+numberFr+"\nChecked in? "+checkIn)
  106.  
  107.                     .setPositiveButton(android.R.string.ok, null)
  108.  
  109.                 .setCancelable(false)
  110.  
  111.                 .create()
  112.  
  113.                 .show();
  114.  
  115.  
  116.  
  117.                        
  118.  
  119.                                 }catch (Exception e){
  120.  
  121.                             new AlertDialog.Builder(theApp)
  122.  
  123.                             .setTitle("Oh F#@K!")
  124.  
  125.                             .setMessage("Failed to get your data! =[")
  126.  
  127.                             .setPositiveButton(android.R.string.ok, null)
  128.  
  129.                         .setCancelable(false)
  130.  
  131.                         .create()
  132.  
  133.                         .show();
  134.  
  135.                                 }
  136.  
  137.             }
  138.  
  139.            
  140.  
  141.         }
  142.  
  143.  
  144.  
  145.     @Override
  146.  
  147.    
  148.  
  149.     public void onCreate(Bundle icicle) {
  150.  
  151.         super.onCreate(icicle);
  152.  
  153.        
  154.  
  155.         setContentView(R.layout.main);
  156.  
  157.         final TextView lul =  (TextView) findViewById(R.id.lul);
  158.  
  159.         final WebView browser = (WebView) findViewById(R.id.webview);
  160.  
  161.         browser.getSettings().setJavaScriptEnabled(true);
  162.  
  163.         browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
  164.  
  165.  
  166.  
  167.         browser.setWebViewClient(new WebViewClient() {
  168.  
  169.             public void onPageFinished(WebView webview, String urla){
  170.  
  171.                 String b = browser.getUrl();
  172.  
  173.                 if(b.equals("http://www.lockerz.com/myLocker")){
  174.  
  175.                     browser.loadUrl("javascript&#058;window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
  176.  
  177.                     lul.setText("Your Locker!");
  178.  
  179.                 }else{
  180.  
  181.                         lul.setText("Login page?");
  182.  
  183.                 }
  184.  
  185.             }
  186.  
  187.         });
  188.  
  189.         browser.loadUrl(urla);
  190.  
  191.     }  
  192.  
  193. }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


In the first proper functional release of 1.0; I am hoping it will contain the following:

> Multiple tabs, switchable at the top of the app
> A tab that has the values of the account (PTZ, friends added, checked in?, dailies)... A refresh button would be needed
> A tab which displays the dailies in an orderly fashion
> A tab to browse the redeemable prizes (possibly)
> Remembered login... Start app>get and login with saved credentials (do while progress bar is showing)>presented with account stats
> Notification of undone dailies and "check in" (possibly very later on; end of my list sort of thing)
> Very nice GUI, with the flowing purple theme and "Lockerz" styled icons

But this is all a little while off... My concept I have posted is practically a 0.1



Hope you all like =]
BLAKE.AnRKist
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Feb 19, 2010 11:49 am

Top

Postby DMacATTACK » Wed Mar 17, 2010 11:14 pm

I really like this idea.
Although, it may be an idea to look into using an API. That is if the website has one (unlikely).
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 5 guests