Skip to content

Commit

Permalink
Added A and B axis buttons, and few enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevy committed Apr 17, 2018
1 parent 77f3bdd commit e2b3220
Show file tree
Hide file tree
Showing 37 changed files with 468 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

Expand Down
26 changes: 9 additions & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".BluetoothConnectionActivity"
android:label="@string/app_name"
Expand All @@ -47,16 +46,14 @@
android:supportsPictureInPicture="false"
android:theme="@style/AppTheme.NoActionBar"
tools:targetApi="n" />

<activity
android:name=".UsbConnectionActivity"
android:label="@string/app_name"
android:resizeableActivity="false"
android:supportsPictureInPicture="false"
android:screenOrientation="portrait"
android:supportsPictureInPicture="false"
android:theme="@style/AppTheme.NoActionBar"
tools:targetApi="n" />

<activity
android:name=".DeviceListActivity"
android:configChanges="orientation|keyboardHidden"
Expand All @@ -71,7 +68,6 @@
android:screenOrientation="portrait"
android:supportsPictureInPicture="false"
tools:targetApi="n" />

<activity
android:name=".AboutActivity"
android:resizeableActivity="false"
Expand All @@ -83,34 +79,30 @@
android:name=".service.GrblUsbSerialService"
android:enabled="true"
android:exported="false" />

<service
android:name=".service.GrblBluetoothSerialService"
android:enabled="true"
android:exported="false" />

<service
android:name=".service.FileStreamerIntentService"
android:exported="false" />

<service
android:name=".service.MyFirebaseInstanceIDService">
<service android:name=".service.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>

<service
android:name=".service.MyFirebaseMessagingService">
<service android:name=".service.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<meta-data android:name="io.fabric.ApiKey" android:value="6d7003aa8ac3717a95dc5c77c2da4bf5ad8c74ff" />
<meta-data
android:name="io.fabric.ApiKey"
android:value="6d7003aa8ac3717a95dc5c77c2da4bf5ad8c74ff" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
android:value="@string/default_notification_channel_id" />

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import android.view.Menu;
import android.view.MenuItem;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.joanzapata.iconify.IconDrawable;
Expand All @@ -47,6 +48,7 @@
import org.greenrobot.eventbus.ThreadMode;

import java.lang.ref.WeakReference;
import java.util.Objects;

import in.co.gorest.grblcontroller.events.BluetoothDisconnectEvent;
import in.co.gorest.grblcontroller.events.GrblSettingMessageEvent;
Expand Down Expand Up @@ -259,7 +261,7 @@ private static class GrblServiceMessageHandler extends Handler {

private final WeakReference<BluetoothConnectionActivity> mActivity;

public GrblServiceMessageHandler(BluetoothConnectionActivity activity){
GrblServiceMessageHandler(BluetoothConnectionActivity activity){
mActivity = new WeakReference<>(activity);
}

Expand Down Expand Up @@ -360,10 +362,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case Constants.CONNECT_DEVICE_INSECURE:
if(resultCode == Activity.RESULT_OK){

String macAddress = data.getExtras().getString(DeviceListActivity . EXTRA_DEVICE_ADDRESS);
if(grblBluetoothSerialService != null && bluetoothAdapter.isEnabled()){
sharedPref.edit().putString(getString(R.string.preference_last_connected_device), macAddress).apply();
connectToDevice(macAddress);
try{
String macAddress = Objects.requireNonNull(data.getExtras()).getString(DeviceListActivity . EXTRA_DEVICE_ADDRESS);
if(grblBluetoothSerialService != null && bluetoothAdapter.isEnabled()){
sharedPref.edit().putString(getString(R.string.preference_last_connected_device), macAddress).apply();
connectToDevice(macAddress);
}

}catch (NullPointerException e){
Crashlytics.logException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import android.view.View;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.toolbox.JsonObjectRequest;
import com.crashlytics.android.Crashlytics;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.Iconify;
Expand All @@ -58,7 +56,6 @@
import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

import in.co.gorest.grblcontroller.databinding.ActivityMainBinding;
import in.co.gorest.grblcontroller.events.ConsoleMessageEvent;
Expand Down Expand Up @@ -155,8 +152,6 @@ public void onDestroy(){
FileSenderListener.resetClass();
MachineStatusListener.resetClass();
isAppRunning = false;

GrblController.getInstance().cancelPendingRequests(GrblController.class.getSimpleName());
}

@Override
Expand Down
66 changes: 28 additions & 38 deletions app/src/main/java/in/co/gorest/grblcontroller/GrblController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,61 @@


import android.app.Application;
import android.content.Context;
import android.support.v7.app.AppCompatDelegate;
import android.text.TextUtils;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.core.CrashlyticsCore;

import in.co.gorest.grblcontroller.util.GoRestBitmapCache;
import in.co.gorest.grblcontroller.network.GoRestService;
import io.fabric.sdk.android.Fabric;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class GrblController extends Application {

private final String TAG = GrblController.class.getSimpleName();
private static GrblController grblController;
private RequestQueue requestQueue;
private ImageLoader imageLoader;
private GoRestService goRestService;

@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics(), new Answers());

configureCrashReporting();

grblController = this;

// Picasso.Builder builder = new Picasso.Builder(this);
// builder.downloader(new OkHttp3Downloader(this, Integer.MAX_VALUE));
// Picasso picasso = builder.build();
// picasso.setIndicatorsEnabled(BuildConfig.DEBUG);
// picasso.setLoggingEnabled(BuildConfig.DEBUG);
// Picasso.setSingletonInstance(picasso);

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

public static synchronized GrblController getInstance(){
return grblController;
}

public RequestQueue getRequestQueue(){
if(requestQueue == null) requestQueue = Volley.newRequestQueue(getApplicationContext());

return requestQueue;
}

public ImageLoader getImageLoader(){
getRequestQueue();
if(imageLoader == null){
imageLoader = new ImageLoader(this.requestQueue, new GoRestBitmapCache());
}

return this.imageLoader;
private void configureCrashReporting(){
CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build(), new Answers());
}

public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public GoRestService getRetrofit(){
if(goRestService == null){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://gorest.co.in")
.addConverterFactory(GsonConverterFactory.create())
.build();

public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
if (requestQueue != null) {
requestQueue.cancelAll(tag);
goRestService = retrofit.create(GoRestService.class);
}
}

return goRestService;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin

if(key.equalsIgnoreCase(getString(R.string.preference_gcode_file_picker_type))){
String value = sharedPreferences.getString(key, "");
if(value != null && value.equalsIgnoreCase("full")){
if(value.equalsIgnoreCase("full")){
EventBus.getDefault().post(new UiToastEvent(getString(R.string.text_only_internal_storage_supported)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,14 @@ public void handleMessage(Message msg) {
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {

String intentAction = intent.getAction();
if(intentAction == null){
grblToast("Unknown error");
return;
}

switch (intentAction) {
case GrblUsbSerialService.ACTION_USB_PERMISSION_GRANTED: // USB PERMISSION GRANTED
if(getSupportActionBar() != null) getSupportActionBar().setSubtitle(getString(R.string.text_connected));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class GrblSettingMessageEvent {

private final GrblLookups lookups;
private final String message;
private final static Pattern MESSAGE_REGEX = Pattern.compile("(\\$\\d+)=([^ ]*)\\s?\\(?([^\\)]*)?\\)?");
private final static Pattern MESSAGE_REGEX = Pattern.compile("(\\$\\d+)=([^ ]*)\\s?\\(?([^)]*)?\\)?");

private String setting;
private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
package in.co.gorest.grblcontroller.helpers;


import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.view.View;

class DepthPageTransformer implements ViewPager.PageTransformer{

private static final float MIN_SCALE = 0.75f;

public void transformPage(View view, float position) {
public void transformPage(@NonNull View view, float position) {
int pageWidth = view.getWidth();

if (position < -1) { // [-Infinity,-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package in.co.gorest.grblcontroller.helpers;

import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.view.View;

Expand All @@ -39,7 +40,7 @@ public ReaderViewPagerTransformer(TransformType transformType) {
private static final float SCALE_FACTOR_SLIDE = 0.85f;
private static final float MIN_ALPHA_SLIDE = 0.35f;

public void transformPage(View page, float position) {
public void transformPage(@NonNull View page, float position) {
final float alpha;
final float scale;
final float translationX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

package in.co.gorest.grblcontroller.helpers;

import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.view.View;

class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;

public void transformPage(View view, float position) {
public void transformPage(@NonNull View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public abstract class SerialCommunicationHandler extends Handler {
private static GrblLookups GrblAlarms;
private static GrblLookups GrblSettings;

private String[] startUpCommands = {GrblUtils.GRBL_BUILD_INFO_COMMAND, GrblUtils.GRBL_VIEW_SETTINGS_COMMAND, GrblUtils.GRBL_VIEW_PARSER_STATE_COMMAND, GrblUtils.GRBL_VIEW_GCODE_PARAMETERS_COMMAND};
private final String[] startUpCommands = {GrblUtils.GRBL_BUILD_INFO_COMMAND, GrblUtils.GRBL_VIEW_SETTINGS_COMMAND, GrblUtils.GRBL_VIEW_PARSER_STATE_COMMAND, GrblUtils.GRBL_VIEW_GCODE_PARAMETERS_COMMAND};

public SerialCommunicationHandler(){

Expand Down Expand Up @@ -225,6 +225,7 @@ private synchronized void updateMachineStatus(String statusMessage){
machineStatus.setMachinePosition(MPos);
machineStatus.setWorkPosition(WPos);
machineStatus.setWorkCoordsOffset(WCO);

if(!enabledPinsChanged) machineStatus.setEnabledPins("");

if(hasOverrides){
Expand Down
Loading

0 comments on commit e2b3220

Please sign in to comment.