Skip to content

Commit

Permalink
Merge pull request #67 from victordiaz/develop
Browse files Browse the repository at this point in the history
Merge version 1.2.8
  • Loading branch information
victordiaz authored Aug 5, 2020
2 parents c923cd5 + b677df8 commit 23db514
Show file tree
Hide file tree
Showing 54 changed files with 1,239 additions and 1,051 deletions.
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
}

project.ext {
versionCode = 127
versionName = "1.2.7"
versionCode = 130
versionName = "1.2.8"
}

task hello {
Expand All @@ -25,6 +25,4 @@ allprojects {
jcenter()
maven { url 'https://jitpack.io' }
}
}

//apply plugin: 'com.github.ben-manes.versions'
}
12 changes: 12 additions & 0 deletions phonk_app/src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
1.2.8
- Decimals method in slider and knob now works
- Launch other scripts via app.launchScript(path) method
- Scan WIFI networks using network.wifiScan(callback)
- MQTT uses now async calls
- console.adbLog() method (for debug purposes)
- camera is now less distorted
- ui.background changes the status bar color too
- OSM maps work now on 4.x.x devices
- SMS send works properly in extended version
- Theming and styling is improved internally

1.2.7
- Better notifications in WebEditor
- Better NFC handling
Expand Down
1 change: 1 addition & 0 deletions phonk_app/src/main/java/io/phonk/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ protected void onCreate(Bundle savedInstanceState) {

// PhonkAppHelper.launchScript(this, new Project("playground/User Projects/grid"));
// PhonkAppHelper.launchScript(this, new Project("examples/Graphical User Interface/Basic Views"));
// PhonkAppHelper.launchScript(this, new Project("examples/Graphical User Interface/Styling & Theming"));
// PhonkAppHelper.launchScript(this, new Project("examples/Graphical User Interface/Extra Views"));
}

Expand Down
1 change: 1 addition & 0 deletions phonk_app/src/main/java/io/phonk/WelcomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public void goToStep(int step) {
// Write a shared pref to never come back here
SharedPreferences userDetails = getSharedPreferences("io.phonk", MODE_PRIVATE);
userDetails.edit().putBoolean(getResources().getString(R.string.pref_is_first_launch), false).commit();
userDetails.edit().putInt("last_version_reinstalled", BuildConfig.VERSION_CODE).commit();

// first time id
UserPreferences.getInstance().set("user_id", StrUtils.generateUUID()).save();
Expand Down
23 changes: 13 additions & 10 deletions phonk_app/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

<RelativeLayout
android:id="@+id/header"
android:background="@color/phonk_backgroundColor"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:alpha="1"
android:padding="5dp"
android:paddingBottom="100dp"
android:animateLayoutChanges="true">
android:animateLayoutChanges="true"
android:background="@color/phonk_backgroundColor"
android:padding="0dp"
android:paddingBottom="0dp">

<!--
<ImageView
Expand Down Expand Up @@ -103,9 +103,9 @@
android:id="@+id/more_options"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="12dp"
android:layout_marginLeft="12dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:src="@drawable/ic_more_vert_white_24dp"
android:text=""
android:textOff=""
Expand All @@ -118,7 +118,10 @@
android:layout_height="wrap_content"
android:layout_below="@id/logo_area"
android:gravity="center_horizontal"
android:minWidth="200dp">
android:minWidth="200dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp">

<!--
<include
Expand All @@ -135,12 +138,12 @@

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_height="0dp"
android:layout_below="@id/infoLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="100dp"
android:layout_marginTop="40dp"
android:layout_marginTop="10dp"
android:layout_marginRight="100dp"
android:background="@color/phonk_colorSecondary_shade_1" />

Expand Down
1 change: 1 addition & 0 deletions phonk_app/src/main/res/layout/projectlist_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:background="@color/phonk_backgroundColor" >

<include
Expand Down
2 changes: 1 addition & 1 deletion phonk_apprunner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ dependencies {
api 'com.github.japgolly.android:svg-android:2.0.6' //'files('libs/androidsvg-1.2.1.jar')

// osmdroid
api 'org.osmdroid:osmdroid-android:6.1.6'
api 'org.osmdroid:osmdroid-android:6.1.8'
// api 'com.github.MKergall.osmbonuspack:OSMBonusPack:v5.7'

// hardware stuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Point;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
Expand Down Expand Up @@ -198,7 +199,6 @@ protected void setupActivity() {
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
setScreenAlwaysOn(mSettingScreenAlwaysOn);

}

@Override
Expand Down Expand Up @@ -271,6 +271,8 @@ public void unregisterEventBus() {
}

private void addDebugFragment() {
MLog.d("qq", "adding debug fragment");

mDebugFragment = DebugFragment.newInstance();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
FrameLayout fl = findViewById(R.id.debug_fragment);
Expand Down Expand Up @@ -542,7 +544,7 @@ public void onEventMainThread(Events.LogEvent e) {
i.putExtra("data", data);
sendBroadcast(i);

MLog.d("action", action);
MLog.d("qq action", action + " " + data);
if ((action == "log_error" || action == "log_permission_error") && !debugFramentIsVisible)
addDebugFragment();
else if (action == "show") addDebugFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;

import io.phonk.runner.AppRunnerActivity;
import io.phonk.runner.AppRunnerLauncherService;
import io.phonk.runner.BuildConfig;
import io.phonk.runner.R;
import io.phonk.runner.apidoc.annotation.PhonkField;
Expand Down Expand Up @@ -498,6 +499,25 @@ public void startActivity(NativeObject params) throws JSONException {
// getActivity().startActivityForResult();
}

/**
* Launch a PHONK script as follows
*
* app.launchScript('examples/Graphical User Interface/Basic Views')
* @param path
*/
@PhonkMethod
public void launchScript(String path) {
Project p = new Project(path);
Intent intent = new Intent(getContext(), AppRunnerLauncherService.class);
// intent.putExtra(Project.SERVER_PORT, PhonkSettings.HTTP_PORT);
intent.putExtra(Project.FOLDER, p.getFolder());
intent.putExtra(Project.NAME, p.getName());
// intent.putExtra(Project.DEVICE_ID, (String) UserPreferences.getInstance().get("device_id"));
// intent.putExtra(Project.SETTINGS_SCREEN_WAKEUP, (Boolean) UserPreferences.getInstance().get("device_wakeup_on_play"));
// EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_RUNNING, p));
getContext().startService(intent);
}

/**
* Callback called when script is loaded
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.phonk.runner.apprunner.interpreter.AppRunnerInterpreter;
import io.phonk.runner.base.events.Events;
import io.phonk.runner.base.utils.GSONUtil;
import io.phonk.runner.base.utils.MLog;
import io.phonk.runner.base.utils.StrUtils;

@PhonkObject
Expand Down Expand Up @@ -86,6 +87,7 @@ public PConsole error(Object outputs) {
}

public PConsole p_error(int type, Object outputs) {
MLog.d("qq", "" + type);

switch (type) {
case AppRunnerInterpreter.RESULT_ERROR:
Expand All @@ -97,7 +99,7 @@ public PConsole p_error(int type, Object outputs) {
break;

case AppRunnerInterpreter.RESULT_NOT_CAPABLE:
base_log("log_error", "This device does not support " + outputs);
base_log("log_error", "This device does not support/have " + outputs);
}

return this;
Expand Down Expand Up @@ -241,6 +243,10 @@ private String getCurrentTime() {
return s.format(new Date());
}

public void adbLog(String tag, String msg) {
MLog.d(tag, msg);
}

public void __stop() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import android.content.res.Configuration;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.Camera;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.hardware.input.InputManager;
import android.net.Uri;
import android.os.BatteryManager;
Expand All @@ -48,14 +46,11 @@
import android.provider.Settings.Secure;
import android.telephony.SmsManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyEvent;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationManagerCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -596,10 +591,10 @@ public String getFromClipboard(String label, String text) {
@PhonkMethod
public void battery(final ReturnInterface callback) {
batteryReceiver = new BroadcastReceiver() {
int scale = -1;
int level = -1;
int voltage = -1;
int temp = -1;
float scale = -1;
float level = -1;
float voltage = -1;
float temp = -1;
boolean isConnected = false;
private int status;
private final boolean alreadyKilled = false;
Expand All @@ -622,10 +617,13 @@ public void onReceive(Context context, Intent intent) {
ReturnObject o = new ReturnObject();

o.put("level", level);
o.put("temperature", temp);
o.put("connected", isConnected);
o.put("scale", scale);
o.put("temperature", temp);

// some devices output mV instead of V
// https://stackoverflow.com/questions/24500795/android-battery-voltage-unit-discrepancies
if (voltage > 1000) voltage = voltage / 1000;
o.put("voltage", voltage);

callback.event(o);
Expand Down Expand Up @@ -732,8 +730,8 @@ public ReturnObject info() {
ret.put("maxMem", Runtime.getRuntime().maxMemory());

PackageManager pm = getContext().getPackageManager();
ret.put("backCamera", pm.hasSystemFeature(PackageManager.FEATURE_CAMERA));
ret.put("frontCamera", pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));
ret.put("cameraBack", pm.hasSystemFeature(PackageManager.FEATURE_CAMERA));
ret.put("cameraFront", pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));
ret.put("cameraFlash", pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH));
ret.put("bluetooth", pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH));
ret.put("bluetoothLE", pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import io.phonk.runner.apidoc.annotation.PhonkMethod;
Expand Down Expand Up @@ -303,7 +304,6 @@ public void zip(final String fOrigin, final String fDestiny, final ReturnInterfa
returnValues(null, callback);
});
t.start();

}

@PhonkMethod(description = "Unzip a file into a folder", example = "")
Expand Down Expand Up @@ -369,6 +369,25 @@ public void __stop() {
}
}

public void saveImage(Bitmap finalBitmap, String fileName, String type, int quality) {
String filePath = getAppRunner().getProject().getFullPathForFile(fileName);

Bitmap.CompressFormat formatType;
if (type.equals("jpg")) formatType = Bitmap.CompressFormat.JPEG;
else formatType = Bitmap.CompressFormat.PNG;

File file = new File(filePath);
if (file.exists()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(formatType, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}

@PhonkMethod(description = "Observer file changes in a folder", example = "")
@PhonkMethodParam(params = {"path", "function(action, file"})
public PFileObserver createFileObserver(String path) {
Expand Down
Loading

0 comments on commit 23db514

Please sign in to comment.