Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Load script into template #2

Merged
merged 2 commits into from
Jan 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions LLScript_Repository_Importer.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ android {

defaultConfig {
applicationId "com.trianguloy.llscript.repository"
minSdkVersion 8
targetSdkVersion 20
versionCode 3
versionName "1.2-CustomBuild"
minSdkVersion 9
targetSdkVersion 21
versionCode 5
versionName "1.3-CustomBuild"
}
buildTypes {
release {
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
package="com.trianguloy.llscript.repository" >

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

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:label="@string/app_name"
android:allowBackup="true"
android:supportsRtl="false">
<activity
android:name="com.trianguloy.llscript.repository.webviewer"
android:label="@string/title_activity_webviewer"
Expand All @@ -17,15 +20,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Template"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:exported="true">
<intent-filter>
<action android:name="net.pierrox.lightning_launcher.TEMPLATE"/>
</intent-filter>
</activity>
<activity android:name="net.pierrox.lightning_launcher.template.ApplyTemplates"
<activity android:name="com.app.lukas.template.ApplyTemplate"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"/>
</application>
Expand Down
88 changes: 88 additions & 0 deletions app/src/main/java/com/app/lukas/template/ApplyTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.app.lukas.template;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.trianguloy.llscript.repository.R;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;


/**
* Created by Lukas on 25.01.2015.
* Creates a template containing the script and asks lightning to install it
*/
public class ApplyTemplate extends Activity{

protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
JSONObject script = new JSONObject();
setContentView(R.layout.apply_templates);

File directory = getExternalCacheDir();
try {
script.put("flags",0);
script.put("name","Repository Importer");
script.put("id",2);
InputStream inCode = getResources().openRawResource(R.raw.script);
byte[] buff = new byte[1024];
int read;
final File template = File.createTempFile("Template", "", directory);
ZipInputStream in = new ZipInputStream(getResources().openRawResource(R.raw.template));
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(template));
StringBuilder builder = new StringBuilder();
try {
while ((read = inCode.read(buff))>0){
builder.append(new String(buff, 0, read));
}
script.put("text", new String(builder));
String s = script.toString();

ZipEntry entry;
while ((entry = in.getNextEntry())!=null)
{
out.putNextEntry(entry);
if(!entry.getName().equals("core/scripts/2")) {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
}
else out.write(s.getBytes());
in.closeEntry();
out.closeEntry();
}
out.flush();
out.close();
template.setReadable(true, false);
sendToLL(template.getAbsolutePath());
template.deleteOnExit();
} finally {
inCode.close();
in.close();
out.close();
finish();
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}

}

private void sendToLL(String path) {
Intent intent = new Intent("net.pierrox.lightning_launcher.APPLY_TEMPLATE");
intent.putExtra("p", path);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

/*package*/ class Constants {

/** This script execution is disabled. */
/*package*/ static final int FLAG_DISABLED = 1;

/** The script appears in the lighting app menu. */
/*package*/ static final int FLAG_APP_MENU = 2;

Expand All @@ -15,30 +12,6 @@
/*package*/ static final int FLAG_CUSTOM_MENU = 8;




/** Mandatory: the identifier of the script, should be something like R.raw.your_script */
/*package*/ static final String INTENT_EXTRA_SCRIPT_ID = "i";

/** Optional: or'ed combination of the FLAG_* constants above (default is 0) */
/*package*/ static final String INTENT_EXTRA_SCRIPT_FLAGS = "f";

/** Optional: name of the script (default is the activity name) */
/*package*/ static final String INTENT_EXTRA_SCRIPT_NAME = "n";

/** Optional: execute the script right after loading it (default is false) */
/*package*/ static final String INTENT_EXTRA_EXECUTE_ON_LOAD = "e";

/** Optional: delete the script right after loading and (presumably) executing it.
* This is useful when the script is meant to configure the home screen, create items or
* install some other scripts, and is no longer needed after this initial setup (default is false).
*/
/*package*/ static final String INTENT_EXTRA_DELETE_AFTER_EXECUTION = "d";





/* App constants */
static final String separator = "$%&";
static final int managerVersion = 1;
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/com/trianguloy/llscript/repository/Template.java

This file was deleted.

Loading