Webmaker for Android
Перейти к файлу
Mike Kamermans f83076013b Added docs for setting core environment variables 2015-07-16 18:48:36 -07:00
_docs readme get started 2015-04-15 19:19:32 -04:00
app Add a quick note explaining the change from underscores to dashes when outputting the locale 2015-07-14 13:23:45 -04:00
gradle/wrapper Add npm build to gradle prebuild task 2015-04-03 15:29:08 -07:00
npm_tasks Make "npm run build" work on Windows. 2015-07-15 09:01:17 -04:00
.env.sample Update gitignore for env 2015-06-14 15:02:03 -07:00
.gitignore Update gitignore for env 2015-06-14 15:02:03 -07:00
.jshintrc Fork .jshintrc from mofostyle 2015-06-12 14:18:12 -04:00
.travis.yml Add travis config. All tests passing. Resolves GH-1625 2015-05-20 16:32:10 -07:00
INSTALL.md Update INSTALL instructions w/ Google Play URL 2015-06-16 12:45:40 -07:00
LICENSE Add Mozilla Public License v2 2015-04-06 20:23:13 -04:00
README.md Added docs for setting core environment variables 2015-07-16 18:48:36 -07:00
SUMMARY.md Added docs folder back in 2015-04-15 18:06:24 -04:00
book.js Added docs folder back in 2015-04-15 18:06:24 -04:00
build.gradle Update Gradle & Crosswalk dependencies 2015-06-25 09:05:35 -04:00
gradle.properties add everything for v1 2015-04-03 13:08:51 -04:00
gradlew add everything for v1 2015-04-03 13:08:51 -04:00
gradlew.bat add everything for v1 2015-04-03 13:08:51 -04:00
package.json Make "npm run build" work on Windows. 2015-07-15 09:01:17 -04:00
settings.gradle add everything for v1 2015-04-03 13:08:51 -04:00

README.md

Webmaker for Android

Please file all issues related to Webmaker Android at https://github.com/mozilla/webmaker-core/issues. You can use the android tag if your issue applies specifically to this repo or the Android platform.

Build Status

Mozilla Webmaker's mission is to help enable a new generation of digital creators and webmakers, giving people the tools and skills they need to move from using the Web to actively making the Web. To this end, the Webmaker App is an entry point to the Webmaker community that provides a radically simple interface for creating mobile applications directly on device.

Webmaker for Android

Getting Started

Prerequisites

Before you jump into the code you'll want to download, install, and configure the following:

Clone & Install Dependencies

git clone https://github.com/mozilla/webmaker-android
cd webmaker-android
npm install
npm run build

Specifying a dev environment

In order to override default webmaker-core settings such as id and api endpoints, create an .env file in the webmaker-android root directory, and declare any enviroment overrides you need in that file, then (re)build the webmaker-android project using npm run build.

For example, to run webmaker-android with a different API endpoint, you would make sure the .env file contains:

API_URI=http://alternative.api.endpoint

For more details on which environment variables are used by webmaker-core, please see the webmaker-core default enviroment.

Android

This repository is home to the native Android wrapper for the Webmaker app. webmaker-android is a hybrid mobile application that is primarily web-based (HTML/CSS/JS) but uses this wrapper to communicate with the native Android SDK. To make changes or to test the app, we recommend you use Android Studio.

  • Compile the webview code with npm run build.
  • Install and configure Android Studio
  • Open Android Studio and select "Import Project"
  • If Android Studio asks, choose "Create project from existing sources"
  • Select the "webmaker-android" directory

Once you have the project open, you can run it within an emulator or on any Android device with USB debugging enabled by selecting "Run 'app'" from the "Run" dropdown menu. For more information, please check out the Android SDK documentation.

Because much of the application logic takes place in WebViews, you'll likely want to set up Remote debugging on Android with Chrome.

Web

Each fragment within webmaker-android is actually just a web page! You can find all of the js, css, and static assets in the webmaker-core module. Static files in ./node_modules/webmaker-core/src/dest/ will be copied up to this Android wrapper as part of npm run build.

NOTE:

For local development, it's recommended to use npm link (read more) with a local copy of webmaker-core, in which you'll do any webview related work separately.

When changes are compiled in webmaker-core you'll need to run npm run copy:core before building in Android Studio. Alternatively, you can create a symbolic link from app/src/main/assets/www/ to ./node_modules/webmaker-core/dest/ to avoid having to run this extra command.

Contact Us

IRC: #webmaker on irc.mozilla.org

Forum: https://groups.google.com/forum/#!forum/mozilla.webmaker


Configuration

Changing configuration

You can see all the default configuration in config/defaults.env (within webmaker-core). In order to change something, create a file called .env in your root directory and format configuration as follows:

CONFIG_VALUE='blah'

Turning on production configuration

You will need a production CLIENT_ID for the id.webmaker.org OAuth server to run the app in production mode. Ask @cade or @k88hudson on irc.

If you are deploying/creating a build that should use production configuration, add the following to your .env before running npm run build.

NODE_ENV='PRODUCTION'
CLIENT_ID='xxxxxx'

Network Assets

Webmaker for Android attempts to use network resources as sparingly as possible. In addition, it is important to cover failure and loading states gracefully at all times. To this end, we have a few React components and libraries included in the project to help make this easier:

Interacting with Android APIs

While very few native Android APIs are used throughout the app, there are a few instances where native APIs are exposed to JS and react using the WebAppInterace.java class:

Router

The application uses an Android class called Router to move between activities. Similar to how you can pass parameters in a URL router like Express, the Android Router class can provide route parameters via the router.js mixin. When using the mixin, route parameters will be bound to route within the react class's state.

var router = require('./lib/router.js');

var MyThing = React.createClass({
  mixins: [router],
  // ...
  componentWillMount: function () {
    console.log(this.state.route);
  }
});

SharedPreferences

SharedPreferences is a simple key/value store API native to Android that can be used to persist values to disk that are only available to the Webmaker application. You can both set and get values to SharedPreferences using Java <-> JS bindings that are provided within WebAppInterface.java:

if (window.Android) {
  window.Android.setSharedPreferences('my::cache::key', 'foobar');
  var hit = window.Android.getSharedPreferences('my::cache::key');
  console.log(hit); // prints "foobar"
}

SharedPreferences is automatically namespaced to the current activity. You can override this behavior by passing true to the optional "global" parameter:

window.Android.getSharedPreferences('state', true);

LRU Cache

MemStorage is a single LRUCache instance that is provided as a singleton. This can be used to persist values to memory that are not needed in-between app sessions. You can both set and get values to MemStorage using Java <-> JS bindings that are provided within WebAppInterface.java:

if (window.Android) {
  window.Android.setMemStorage('my::cache::key', 'foobar', false);
  var hit = window.Android.getMemStorage('my::cache::key', false);
  console.log(hit); // prints "foobar"
}

MemStorage is automatically namespaced to the current activity. You can override this behavior by passing true to the optional "global" parameter:

window.Android.getMemStorage('state', true);

Google Analytics Event Firing

This function allows you to send event data to Google Analytics by calling the trackEvent() method. Optionally you can specify a numeric value (int) to pass along in your event, however this isn't required. Please see the below code for example implementation.

You can read more about the parameters and what they do here: https://developers.google.com/analytics/devguides/collection/android/v4/events

if (window.Android) {
    window.Android.trackEvent('category', 'action', 'label');
    window.Android.trackEvent('category', 'action', 'label', 'value'); // optional value
}