World of Bleach - Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Android: Your First App! WoB Wrapper

3 posters

Go down

Android: Your First App! WoB Wrapper Empty Android: Your First App! WoB Wrapper

Post by My420Time Thu Dec 02, 2010 10:31 am

Prerequisites:
Java JRE:
http://www.oracle.com/technetwork/java/javase/downloads/index.html

Android SDK(Follow guide and install Eclipse + ADT):
http://developer.android.com/sdk/installing.html

Ok, so I am going to assume if your reading this you've installed the Java JRE, Eclipse, ADT, and have a copy of the latest android SDK on hand!

Step 1:
Fire up Eclipse and wait for it to fully load. Once loaded click File -> New Android Project.

Step 2:
Fill out all the information here.
Project Name: WoB Wrapper
Build Target: Android 2.2 (I picked this since its the latest sdk.. you can use the google ones if you want to add maps/what not)
Application Name: World of Bleach Wrapper
Package Name: my420Time.Wob_Wrapper
Create Activity: Main
Min SDK Version: 3
-> Finish

Step 3:
Now navigate to our newly created package and expand res -> layout -> main.xml. Paste the code below into Main.xml. All we are doing here is setting up a basic web gui. Android is awesome about making things easy!

Code:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>



Step 4:
Now navigate to our package and expand src -> my420time.Wob_Wrapper -> Main.java. Paste the code below into your Main.java file.

Code:


package my420time.Wob_Wrapper;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Main extends Activity {

    /** Called when the activity is first created. */
   //define our webview
   WebView webview;
   //define for menu option order
   private static final int MENU_QUIT = 1;
   
   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Remove the title bar with our application name.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // Display our xml file we set up
        setContentView(R.layout.main);
        // Attach our defined webview to our layout
        webview = (WebView)findViewById(R.id.webview);
        // Turn java on for our newly created webview
        webview.getSettings().setJavaScriptEnabled(true);
        // Set where our webview will launch
        webview.loadUrl("http://worldofbleach-rpg.com/");
        // Watch if we are connected to the internet or not
        // Not needed anymore on newer SDK
        http://WebView.enablePlatformNotifications();
        // Launch our application's webview
        webview.setWebViewClient(new WoBClient());
    }
   
   /* Creates the menu items */
   public boolean onCreateOptionsMenu(Menu menu) {
      //Tells android what to show when we press the menu button.
       menu.add(0, MENU_QUIT, 0, "Quit");
       return true;
   }

   /* Handles item selections */
   public boolean onOptionsItemSelected(MenuItem item) {
       switch (item.getItemId()) {
       case MENU_QUIT:
         //Close down when pressed
          finish();
        return true;
       }
       return false;
   }
   
   @Override
   //Capture when the phystical back key is hit
   public boolean onKeyDown(int keyCode, KeyEvent event) {
       if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
          webview.goBack();
           return true;
       }
       return super.onKeyDown(keyCode, event);
   }
   
   private class WoBClient extends WebViewClient {
       @Override
       public boolean shouldOverrideUrlLoading(WebView view, String url) {
          view.loadUrl(url);
           return true;
       }
   }
}


Step 5:
Navigate to AndroidManifest.xml and paste the code below to tell our application we need access to the internet!

Code:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="my420time.Wob_Wrapper"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Main"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="3" />
  <uses-permission android:name="android.permission.INTERNET" />
</manifest>


Step 6:
Right click "WoB Wrapper" (The project) and click Run As -> Android Application. Congrats you've written your first android application! (You can also have it save a signed/unsigned apk for the market/your phone)
My420Time
My420Time
Human
Human

Posts : 3
Join date : 2010-11-28

Back to top Go down

Android: Your First App! WoB Wrapper Empty Re: Android: Your First App! WoB Wrapper

Post by Lsmjudoka Thu Dec 09, 2010 1:03 pm

-Somewhat skeptical of posting a public WoB wrapper app for anyone to steal D:-
Lsmjudoka
Lsmjudoka
Administrator
Administrator

Posts : 470
Join date : 2010-01-22

Back to top Go down

Android: Your First App! WoB Wrapper Empty Re: Android: Your First App! WoB Wrapper

Post by My420Time Fri Dec 10, 2010 8:27 pm

Lsmjudoka wrote:-Somewhat skeptical of posting a public WoB wrapper app for anyone to steal D:-

Ya, I don't plan to release my real version of the WoB app. ^_^ You'll have access to the source of course but won't be posted publicly. It is taking quite a bit of work to make it look nice and function like I want. This is just a very very basic http wrapper, which is the equivalent of opening the browser on your phone.
My420Time
My420Time
Human
Human

Posts : 3
Join date : 2010-11-28

Back to top Go down

Android: Your First App! WoB Wrapper Empty Re: Android: Your First App! WoB Wrapper

Post by Lsmjudoka Sat Dec 11, 2010 5:37 am

After using it, I see Smile Sounds good.
Lsmjudoka
Lsmjudoka
Administrator
Administrator

Posts : 470
Join date : 2010-01-22

Back to top Go down

Android: Your First App! WoB Wrapper Empty Re: Android: Your First App! WoB Wrapper

Post by Lsmjudoka Thu Dec 30, 2010 6:19 am

You should post a "Hello Android" tutorial though, that might be more helpful ^^ Although right now I'd just like to know how to do basic i/o. Nothing seems to be basic in Android though D:
Lsmjudoka
Lsmjudoka
Administrator
Administrator

Posts : 470
Join date : 2010-01-22

Back to top Go down

Android: Your First App! WoB Wrapper Empty Re: Android: Your First App! WoB Wrapper

Post by My420Time Thu Dec 30, 2010 7:12 am

Well, for basic I/O what exactly do you want to do? Have a settings file, read contacts, read/write files from the SDCard, and there are a few more gimme an idea. I'll write up a Hello world app as these are pretty generic in most languages. Then add functions to that in new replies on it.
My420Time
My420Time
Human
Human

Posts : 3
Join date : 2010-11-28

Back to top Go down

Android: Your First App! WoB Wrapper Empty Re: Android: Your First App! WoB Wrapper

Post by Break Thu Dec 30, 2010 2:16 pm

don't forget the ! on "hello world" if a program is worth writing, it's worth writing enthusiastically :P
Break
Break
Student
Student

Posts : 128
Join date : 2010-09-28
Age : 35
Location : Texas

Back to top Go down

Android: Your First App! WoB Wrapper Empty Re: Android: Your First App! WoB Wrapper

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum