Skip to content

Commit

Permalink
Merge pull request #73 from victordiaz/develop
Browse files Browse the repository at this point in the history
Merge for 1.2.9
  • Loading branch information
victordiaz authored Aug 7, 2020
2 parents 23db514 + 742a9b8 commit 204a461
Show file tree
Hide file tree
Showing 29 changed files with 299 additions and 284 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
}

project.ext {
versionCode = 130
versionName = "1.2.8"
versionCode = 131
versionName = "1.2.9"
}

task hello {
Expand Down
9 changes: 9 additions & 0 deletions phonk_app/src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
1.2.9
- Toggle state order are fixed
- Camera methods changed to fix callbacks
- MQTT methods are changed a bit to work better asynchronously. Hopefully it won't change anymore! :)
- Background service now stops properly
- Fixed memory leak in main app
- Custom icons in projects and shortcuts
- Scripts now launch with the same previous orientation. This is nice for tablets!

1.2.8
- Decimals method in slider and knob now works
- Launch other scripts via app.launchScript(path) method
Expand Down
32 changes: 24 additions & 8 deletions phonk_app/src/main/java/io/phonk/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.view.ContextThemeWrapper;
import android.view.MenuItem;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class MainActivity extends BaseActivity {

private static final java.lang.String TAG = MainActivity.class.getSimpleName();

private AppRunnerCustom mAppRunner;
// private AppRunnerCustom mAppRunner;

private Intent mServerIntent;

Expand All @@ -107,10 +108,12 @@ public class MainActivity extends BaseActivity {
private boolean isWebIdeMode = false;

private boolean mUiInit = false;
private PDelay mDelay;
// private PDelay mDelay;

private boolean alreadyStartedServices = false;
private boolean isConfigChanging = false;
private Runnable mDelay;
private Handler mHandler;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -126,8 +129,8 @@ protected void onCreate(Bundle savedInstanceState) {
alreadyStartedServices = savedInstanceState.getBoolean("alreadyStartedServices", false);
}

mAppRunner = new AppRunnerCustom(this);
mAppRunner.initDefaultObjects(AppRunnerHelper.createSettings()).initInterpreter();
// mAppRunner = new AppRunnerCustom(this);
// mAppRunner.initDefaultObjects(AppRunnerHelper.createSettings()).initInterpreter();

// PhonkApp phonkApp = new PhonkApp(mAppRunner);
// phonkApp.network.checkVersion();
Expand All @@ -141,7 +144,18 @@ protected void onCreate(Bundle savedInstanceState) {
loadUI(1);
} else {
loadUI(0);
mDelay = mAppRunner.pUtil.delay(3000, () -> mViewPager.setCurrentItem(1));

mHandler = new Handler();
mDelay = new Runnable() {
@Override
public void run() {
mViewPager.setCurrentItem(1);
mHandler.removeCallbacks(this);
}
};
mHandler.postDelayed(mDelay, 3000);

// mDelay = mAppRunner.pUtil.delay(3000, () -> mViewPager.setCurrentItem(1));
}
setScreenAlwaysOn((boolean) UserPreferences.getInstance().get("screen_always_on"));

Expand Down Expand Up @@ -181,8 +195,9 @@ protected void onPause() {
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
if (mDelay != null) mDelay.stop();
mAppRunner.byebye();
// if (mDelay != null) mDelay.stop();
if (mHandler != null) mHandler.removeCallbacks(mDelay);
// mAppRunner.byebye();

if (!isConfigChanging) stopServers();
}
Expand Down Expand Up @@ -289,7 +304,8 @@ private void loadUI(int toPage) {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (positionOffset > 0.1) {
if (mDelay != null) mDelay.stop();
// if (mDelay != null) mDelay.stop();
if (mHandler != null) mHandler.removeCallbacks(mDelay);
}

if (position == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ public void addTextToConsole(String text) {
handler.post(() -> mComputerText.append(text + "\n> "));
}


// folder choose
@Subscribe
public void onEventMainThread(Events.FolderChosen e) {
Expand Down
84 changes: 2 additions & 82 deletions phonk_app/src/main/java/io/phonk/gui/projectlist/ProjectItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class ProjectItem extends LinearLayout {
public ProjectItem(Context context, boolean listMode) {
super(context);
this.mContext = context;
//this.mPlf = plf;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

if (listMode) {
Expand All @@ -86,17 +85,8 @@ public ProjectItem(Context context, boolean listMode) {
customIcon = mItemView.findViewById(R.id.iconImg);

this.setOnClickListener(v -> {
/*
AnimatorSet animSpin;
animSpin = (AnimatorSet) AnimatorInflater.loadAnimator(v.getContext(), R.animator.run);
animSpin.setTarget(v);
animSpin.start();
*/

Runnable r = () -> {
PhonkAppHelper.launchScript(getContext(), mProject);
// getActivity().overridePendingTransition(R.anim.splash_slide_in_anim_set,
// R.anim.splash_slide_out_anim_set);
};

Handler handler = new Handler();
Expand All @@ -116,41 +106,6 @@ public void setText(String text) {
textViewName.setText(text);
}

public void reInit(String text, boolean selected) {
setText(text);
// TODO reenable this setHighlighted(selected);
}

public void drawText(ImageView imageView, String t2) {

// ImageView myImageView =
Bitmap myBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.RGB_565);
Paint myPaint = new Paint();
myPaint.setColor(Color.BLUE);
myPaint.setAntiAlias(true);
myPaint.setTextSize(80);

int x1 = 10;
int y1 = 80;
int x2 = 20;
int y2 = 20;

// Create mContext new image bitmap and attach a brand new canvas to it
Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565);
Canvas tempCanvas = new Canvas(tempBitmap);

// Draw the image bitmap into the cavas
tempCanvas.drawBitmap(myBitmap, 0, 0, null);

// Draw everything else you want into the canvas, in this example mContext
// rectangle with rounded edges
tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myPaint);
tempCanvas.drawText(t2.substring(0, 1).toUpperCase(), x1, y1, myPaint);

// Attach the canvas to the ImageView
imageView.setImageDrawable(new BitmapDrawable(getResources(), tempBitmap));
}

public void setMenu() {
// setting menu for mProject.getName());
mMenuButton = findViewById(R.id.card_menu_button);
Expand All @@ -161,34 +116,22 @@ public void setMenu() {
return true;
});

//customIcon.setOnCreateContextMenuListener();
mMenuButton.setOnClickListener(v -> showMenu(mMenuButton));
// this.setOnLongClickListener(new OnLongClickListener() {
// @Override
// public boolean onLongClick(View v) {
// showContextMenu();
// return true;
// }
// });
}

private void showMenu(View fromView) {
Context wrapper = new ContextThemeWrapper(mContext, R.style.phonk_PopupMenu);
PopupMenu myPopup = new PopupMenu(wrapper, fromView);
myPopup.inflate(R.menu.project_actions);
myPopup.setOnMenuItemClickListener(menuItem -> {

int itemId = menuItem.getItemId();

switch (itemId) {
case R.id.menu_project_list_run:
// EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_RUN, mProject));
PhonkAppHelper.launchScript(getContext(), mProject);
return true;
case R.id.menu_project_list_edit:
PhonkAppHelper.launchEditor(getContext(), mProject);

// EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_EDIT, mProject));
return true;
case R.id.menu_project_webeditor:
PhonkAppHelper.openInWebEditor(getContext(), mProject);
Expand Down Expand Up @@ -233,21 +176,6 @@ private void showMenu(View fromView) {

}

/*
public Drawable getBg() {
return bg;
}
public void setHighlighted(boolean highlighted) {
if (highlighted) {
getBg().setColorFilter(0x22000000, PorterDuff.Mode.MULTIPLY);
} else {
getBg().clearColorFilter();
}
this.highlighted = highlighted;
}
*/

public boolean isHighlighted() {
return highlighted;
}
Expand All @@ -263,16 +191,8 @@ public void setProjectInfo(Project p) {
setText(p.getName());
setTag(p.getName());

File f = new File(p.getFullPathForFile("icon.png"));
// setImage(R.drawable.primarycolor_rounded_rect);

if (f.exists()) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(f.getPath(), bmOptions);
bitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, true);

setImage(bitmap);
}
Bitmap icon = p.getIcon();
if (icon != null) setImage(icon);
setMenu();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ public int findAppPosByName(String appName) {

for (int i = 0; i < mProjectList.size(); i++) {
String name = mProjectList.get(i).getName();
// MLog.d(TAG, "name " + name);

if (name.equals(appName)) {
pos = i; //(int) mProjectAdapter.getItemId(i);
pos = i;

break;
}
Expand Down
11 changes: 7 additions & 4 deletions phonk_app/src/main/java/io/phonk/helpers/PhonkScriptHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;

Expand Down Expand Up @@ -428,9 +429,6 @@ public static String fileExt(String url) {
public static void addShortcut(Context c, String folder, String name) {
Project p = new Project(folder, name);

Intent.ShortcutIconResource icon;
icon = Intent.ShortcutIconResource.fromContext(c, R.drawable.app_icon);

if (ShortcutManagerCompat.isRequestPinShortcutSupported(c)) {
Intent shortcutIntent = new Intent(c, AppRunnerActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand All @@ -439,10 +437,15 @@ public static void addShortcut(Context c, String folder, String name) {
shortcutIntent.putExtra(Project.FOLDER, p.getFolder());
shortcutIntent.setAction(Intent.ACTION_MAIN);

Bitmap bitmapIcon = p.getIcon();

IconCompat icon = IconCompat.createWithResource(c, R.drawable.app_icon);
if (bitmapIcon != null) icon = IconCompat.createWithBitmap(bitmapIcon);

ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(c, folder + "/" + name)
.setIntent(shortcutIntent) // !!! intent's action must be set on oreo
.setShortLabel(name)
.setIcon(IconCompat.createWithResource(c, R.drawable.app_icon))
.setIcon(icon)
.build();
ShortcutManagerCompat.requestPinShortcut(c, shortcutInfo, null);
}
Expand Down
16 changes: 1 addition & 15 deletions phonk_app/src/main/java/io/phonk/server/PhonkServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,6 @@ public void onCreate() {
mEventsProxy = new EventsProxy();
EventBus.getDefault().register(this);

/*
// go back to app intent
Intent resultIntent = new Intent(this, MainActivity.class);
// The stack object will contain an artificial back stack for
// navigating backward from the Activity leads out your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
*/

// close server intent
Intent notificationIntent = new Intent(this, PhonkServerService.class).setAction(SERVICE_CLOSE);
PendingIntent pendingIntentStopService = PendingIntent.getService(this, (int) System.currentTimeMillis(), notificationIntent, 0);
Expand Down Expand Up @@ -377,7 +364,7 @@ public void onDestroy() {
unregisterReceiver(stopActivitiyBroadcastReceiver);
unregisterReceiver(viewsUpdateBroadcastReceiver);

fileObserver.stopWatching();
if (fileObserver != null) fileObserver.stopWatching();

EventBus.getDefault().unregister(this);
}
Expand Down Expand Up @@ -478,7 +465,6 @@ public void onReceive(Context context, Intent intent) {
}
};


@Subscribe
public void onEventMainThread(Events.ProjectEvent e) {
MLog.d(TAG, "connect -> " + e.getAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public class AppRunnerActivity extends BaseActivity {
private boolean debugFramentIsVisible;
private boolean orientationChanged = false;
private Bundle mBundle;
private boolean isLandscape;
private boolean isPortrait;
private Map<String, Object> scriptSettings;

Expand Down Expand Up @@ -154,15 +153,16 @@ protected void onCreate(Bundle savedInstanceState) {
*/
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
if (size.x > size.y) isLandscape = true;
if (size.x > size.y) isPortrait = false;
else isPortrait = true;

if (orientation.equals("landscape")) { // && !isLandscape) {
if (orientation.equals("landscape")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// orientationChanged = true;
} else if (orientation.equals("portrait")) { // && !isPortrait) {
} else if (orientation.equals("portrait")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// orientationChanged = true;
} else if (orientation.equals("current")) {
if (isPortrait) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

// if we changed the orientation, we will wait for the orientation to change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void onDestroy() {
super.onDestroy();
MLog.d(TAG, "onDestroy");
if (mAppRunner.interp != null) mAppRunner.interp.callJsFunction("onDestroy");
// fileObserver.stopWatching();
if (fileObserver != null) fileObserver.stopWatching();
mAppRunner.byebye();
}

Expand Down
Loading

0 comments on commit 204a461

Please sign in to comment.