Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making an app from a website
Author Message
Deak Phreak Offline
Administrator
*******

Posts: 16
Joined: Mar 2013
Reputation: 1
Post: #1
Making an app from a website
Download the SDK

Load Eclipse

Choose a workspace

Choose a new Android Application Project

Give it an App Name, Project Name and Package Name
Examples:
App: Crochet By Allie Orders
Project: CrochetByAllieOrders
Package: com.spiffynetwork.crochetbyallieorders

Leave everything else as is and hit next

Leave everything as is and hit next

Choose a logo and hit next

Choose Fullscreen Activity and hit next

Hit Finish


It may load a graphical view by default. Below the graphical stuff there should be a tab that says activity_fullscreen.xml which you can click on to view the source

Edit the following files with the following code:

/AndroidManifest.xml
Replace the <uses-sdk section with following
Code:
<uses-permission android:name="android.permission.INTERNET" />

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="10" />


/res/layout/activity_fullscreen.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#000000">
    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
          android:background="#000000"
        android:visibility="visible" >
    <ProgressBar
        android:id="@+id/web_view_progress_bar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="0dip"
          android:background="#000000"
        android:visibility="gone" />
    </WebView>
</RelativeLayout>


/src/PACKAGE NAME/FullscreenActivity.java
edit the URL inside to point to where you want the app to load. Also replace the first line with your correct package name
Code:
package com.spiffynetwork.xbmc;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;



public class FullscreenActivity extends Activity { WebView mWebView; ProgressBar pd = null;
    
    
    
    @SuppressLint("SetJavaScriptEnabled")


    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
    
        setContentView(R.layout.activity_fullscreen);
        pd = (ProgressBar) findViewById(R.id.web_view_progress_bar);
        //final TextView tv = (TextView)findViewById(R.id.web_view_progress_bar_percent);  
        mWebView = (WebView) findViewById(R.id.webview);
    
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setDomStorageEnabled(true);
    
        mWebView.setBackgroundColor(0x00000000);
    
        mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        mWebView.loadUrl("http://crochetbyallie.com");
        mWebView.setWebViewClient(new WebViewClient());        
        mWebView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
               if(progress < 100 && pd.getVisibility() == ProgressBar.GONE){
                 pd.setVisibility(ProgressBar.VISIBLE);
               }
               pd.setProgress(progress);
               if(progress == 100) {
                 pd.setVisibility(ProgressBar.GONE);
               }
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu_options, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
      
        switch (item.getItemId())
        {
            case R.id.menu_refresh:
                mWebView.loadUrl("http://crochetbyallie.com");
            break;
            case R.id.menu_exit:
                doExit();
            break;
        }
        return true;
    }    

    protected void doExit() {
        new AlertDialog.Builder(this)
        .setIcon(android.R.drawable.ic_dialog_alert)
        .setTitle("Exit")
        .setMessage("Are you sure you want to exit?")
        .setPositiveButton("Yes", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();    
            }
    
        })
        .setNegativeButton("No", null)
        .show();
    }

    @Override
    public void onBackPressed(){                  
        if(mWebView.canGoBack()){
            mWebView.goBack();
        } else {
            doExit();
        }
    }

    class ClassWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
    }
}


Right click on the layout folder and choose New -> Android XML File. In the File field, type in "menu_options.xml" and choose the Resource Type to "Menu". Click Finish

/res/menu/menu_options.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Single menu item
         Set id, icon and Title for each menu item
    -->
    <item android:id="@+id/menu_refresh"
          android:title="Refresh" />

    <item android:id="@+id/menu_exit"
          android:title="Exit" />
</menu>

Once you are done, you can either right click on the main folder in the left window and choose Android Tools / Export unsigned package, then use a signing tool to sign it, or click on the play icon in the toolbar if you have a virtual emulator setup (AVD) and once run in there, you should have a package in your workspace/APP/bin folder. For example, mine would be in "C:\Users\Deak Phreak\workspace\CrochetByAllieOrders\bin"

Spiffy Network
08-06-2013 10:15 AM
Find all posts by this user Quote this message in a reply
Post Reply 



Follow Us...

Spiffy Directory