Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
petekanev committed May 4, 2016
1 parent 6c5522b commit c6fac95
Show file tree
Hide file tree
Showing 403 changed files with 34,415 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
@@ -1 +1,8 @@
# ns-androidWidget-App-Demo
# How to run

* Run command in your terminal
```Shell
tns run android
```
* Add the widget from the application WidgetDemo to your home screen.
* Clicking on the button on the right will increase the tap counter, while clicking on the image will open the application with which the widget is associated.
50 changes: 50 additions & 0 deletions app/App_Resources/Android/AndroidManifest.xml
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">

<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>

<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>

<receiver android:name="com.tns.MyWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/my_widget_info" />
</receiver>
</application>
</manifest>
15 changes: 15 additions & 0 deletions app/App_Resources/Android/app.gradle
@@ -0,0 +1,15 @@
// Add your native dependencies here:

// Uncomment to add recyclerview-v7 dependency
//dependencies {
// compile 'com.android.support:recyclerview-v7:+'
//}

android {
defaultConfig {
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Binary file added app/App_Resources/Android/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/Android/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/Android/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/Android/drawable/ns.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions app/App_Resources/Android/layout/my_widget.xml
@@ -0,0 +1,45 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#33000000"
android:padding="8dp">

<ImageView
android:id="@+id/taps_image"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ns"/>

<TextView
android:id="@+id/taps_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:text="0"
android:textColor="#ffffff"
android:textSize="30sp"
android:textStyle="bold" />

<TextView
android:id="@+id/appwidget_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:text="TAPS"
android:textColor="#ffffff"
android:textSize="24sp" />

<Button
android:id="@+id/tap_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="TOUCH ME!"/>

</LinearLayout>
10 changes: 10 additions & 0 deletions app/App_Resources/Android/xml/my_widget_info.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 110x250dp defines minimal area of 2x4 tiles -->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialKeyguardLayout="@layout/my_widget"
android:initialLayout="@layout/my_widget"
android:minHeight="110dp"
android:minWidth="250dp"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="18000000"
android:widgetCategory="home_screen"></appwidget-provider>
Binary file added app/App_Resources/iOS/Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default-667h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default-736h@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default-Landscape.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default-Landscape@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default-Landscape@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default-Portrait.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default-Portrait@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Default@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Icon-Small-50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Icon-Small-50@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Icon-Small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/Icon-Small@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions app/App_Resources/iOS/Info.plist
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>icon.png</string>
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon-40</string>
<string>icon-60</string>
<string>icon-72</string>
<string>icon-76</string>
<string>Icon-Small</string>
<string>Icon-Small-50</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
5 changes: 5 additions & 0 deletions app/App_Resources/iOS/build.xcconfig
@@ -0,0 +1,5 @@
// You can add custom settings here
// for example you can uncomment the following line to force distribution code signing
// CODE_SIGN_IDENTITY = iPhone Distribution
// ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
// ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = Brand Assets;
Binary file added app/App_Resources/iOS/icon-40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/icon-40@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/icon-60.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/icon-60@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/App_Resources/iOS/icon-72.png
Binary file added app/App_Resources/iOS/icon-72@2x.png
Binary file added app/App_Resources/iOS/icon-76.png
Binary file added app/App_Resources/iOS/icon-76@2x.png
Binary file added app/App_Resources/iOS/icon.png
Binary file added app/App_Resources/iOS/icon@2x.png
18 changes: 18 additions & 0 deletions app/app.css
@@ -0,0 +1,18 @@
.title {
font-size: 30;
horizontal-align: center;
margin: 20;
}

button {
font-size: 42;
horizontal-align: center;
}

.message {
font-size: 20;
color: #284848;
horizontal-align: center;
margin: 0 20;
text-align: center;
}
2 changes: 2 additions & 0 deletions app/app.js
@@ -0,0 +1,2 @@
var application = require("application");
application.start({ moduleName: "main-page" });
7 changes: 7 additions & 0 deletions app/main-page.js
@@ -0,0 +1,7 @@
var createViewModel = require("./main-view-model").createViewModel;

function onNavigatingTo(args) {
var page = args.object;
page.bindingContext = createViewModel();
}
exports.onNavigatingTo = onNavigatingTo;
7 changes: 7 additions & 0 deletions app/main-page.xml
@@ -0,0 +1,7 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
<StackLayout>
<Label text="Tap the button" class="title"/>
<Button text="TAP" tap="{{ onTap }}" />
<Label text="{{ message }}" class="message" textWrap="true"/>
</StackLayout>
</Page>
24 changes: 24 additions & 0 deletions app/main-view-model.js
@@ -0,0 +1,24 @@
var Observable = require("data/observable").Observable;

function getMessage(counter) {
if (counter <= 0) {
return "Hoorraaay! You unlocked the NativeScript clicker achievement!";
} else {
return counter + " taps left";
}
}

function createViewModel() {
var viewModel = new Observable();
viewModel.counter = 42;
viewModel.message = getMessage(viewModel.counter);

viewModel.onTap = function() {
this.counter--;
this.set("message", getMessage(this.counter));
}

return viewModel;
}

exports.createViewModel = createViewModel;
46 changes: 46 additions & 0 deletions app/myWidgetClass.js
@@ -0,0 +1,46 @@
(function () {
// yay for JavaScript closures!
var taps = -1;
var R = org.nativescript.widgetDemo.R; // reduces syntax noise, stands for 'android resources'
var rng = new java.util.Random();

android.appwidget.AppWidgetProvider.extend("com.tns.MyWidget", {
// is called each time the widget is added to the homescreen, or update ticks
onUpdate: function (context, appWidgetManager, appWidgetIds) {
console.log("Update called!");
// gets the number of instances of the same widget on the homescreen
var appWidgetsLen = appWidgetIds.length;

taps += 1;

// for each widget - update - we want them to be consistent
for (i = 0; i < appWidgetsLen; i++) {
updateWidget(context, appWidgetManager, appWidgetIds, appWidgetIds[i]);
}
}
});

function updateWidget(context, appWidgetManager, appWidgetIds, widgetId) {
var text = taps.toString();

// retrieve our layout and all its views
var views = new android.widget.RemoteViews(context.getPackageName(), R.layout.my_widget);

views.setTextViewText(R.id.taps_text, text);

var intent = new android.content.Intent(context, com.tns.MyWidget.class);
intent.setAction(android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

var startAppIntent = new android.content.Intent(context, com.tns.NativeScriptActivity.class); // the activity defined in AndroidManifest
startAppIntent.putExtra(android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);

var pI = android.app.PendingIntent.getBroadcast(context, 0, intent, android.app.PendingIntent.FLAG_UPDATE_CURRENT);
var pI2 = android.app.PendingIntent.getActivity(context, 0, startAppIntent, android.app.PendingIntent.FLAG_UPDATE_CURRENT);

views.setOnClickPendingIntent(R.id.tap_button, pI);
views.setOnClickPendingIntent(R.id.taps_image, pI2);

appWidgetManager.updateAppWidget(widgetId, views);
}
})();
1 change: 1 addition & 0 deletions app/package.json
@@ -0,0 +1 @@
{"name":"tns-template-hello-world","main":"app.js","version":"2.0.0","author":{"name":"Telerik","email":"support@telerik.com"},"description":"Nativescript hello-world project template","license":"Apache-2.0","keywords":["telerik","mobile","nativescript","{N}","tns","appbuilder","template"],"repository":{"type":"git","url":"git://github.com/NativeScript/template-hello-world.git"},"bugs":{"url":"https://github.com/NativeScript/template-hello-world/issues"},"homepage":"https://github.com/NativeScript/template-hello-world","android":{"v8Flags":"--expose_gc"},"readme":"ERROR: No README data found!","_id":"tns-template-hello-world@2.0.0","_from":"tns-template-hello-world@2.0.0"}
1 change: 1 addition & 0 deletions app/references.d.ts
@@ -0,0 +1 @@
/// <reference path="../node_modules/tns-core-modules/tns-core-modules.d.ts" /> Enable smart suggestions and completions in Visual Studio Code JavaScript projects.
20 changes: 20 additions & 0 deletions package.json
@@ -0,0 +1,20 @@
{
"description": "NativeScript Application",
"readme": "NativeScript Application",
"nativescript": {
"id": "org.nativescript.widgetDemo",
"tns-android": {
"version": "2.0.0"
}
},
"dependencies": {
"tns-core-modules": "2.0.0-2016-04-18-2684"
},
"devDependencies": {
"babel-traverse": "6.8.0",
"babel-types": "6.8.1",
"babylon": "6.7.0",
"filewalker": "0.1.2",
"lazy": "1.0.11"
}
}
@@ -0,0 +1 @@
#Tue May 03 10:44:18 EEST 2016
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,38 @@
var fs = require("fs"),
path = require("path");
module.exports = function Helpers(config) {

function cleanOutFile(filePath) {
fs.truncateSync(filePath, 0);
if(config && config.logger) {
config.logger.info("+cleared out file: " + filePath);
}
}

function createFile(filePath) {
if(ensureDirectories(filePath)) {
fs.writeFileSync(filePath, "");
if(config && config.logger) {
config.logger.info("+created ast output file: ");
}
}
cleanOutFile(filePath)
}

function ensureDirectories(filePath) {
var parentDir = path.dirname(filePath);
if(fs.existsSync(parentDir)) {
return true;
}

ensureDirectories(parentDir);
fs.mkdirSync(parentDir);
return true;
}

return {
cleanOutFile: cleanOutFile,
createFile: createFile,
ensureDirectories: ensureDirectories
}
};

0 comments on commit c6fac95

Please sign in to comment.