Files
status-react/android/app/src/main/java/com/statusim/MainActivity.java
T

189 lines
6.4 KiB
Java
Raw Normal View History

2016-05-19 18:31:56 +02:00
package com.statusim;
2016-03-23 16:48:26 +02:00
import com.facebook.react.ReactActivity;
2016-04-01 18:05:55 +03:00
import io.realm.react.RealmReactPackage;
import com.oblador.vectoricons.VectorIconsPackage;
2016-03-23 16:48:26 +02:00
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
2016-03-23 17:02:53 +02:00
import com.rt2zz.reactnativecontacts.ReactNativeContacts;
import android.os.Bundle;
2016-06-16 07:23:11 +03:00
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
2016-06-08 12:43:02 +02:00
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnCancelListener;
2016-06-16 07:23:11 +03:00
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.content.Intent;
import android.content.Context;
2016-04-01 18:05:55 +03:00
import com.bitgo.randombytes.RandomBytesPackage;
2016-05-19 20:05:04 +03:00
import com.BV.LinearGradient.LinearGradientPackage;
2016-05-18 17:40:26 +03:00
import com.centaurwarchief.smslistener.SmsListener;
2016-03-23 16:48:26 +02:00
2016-06-16 07:23:11 +03:00
2016-05-26 19:20:39 +03:00
import android.util.Log;
2016-03-23 16:48:26 +02:00
import java.util.Arrays;
import java.util.List;
2016-03-23 17:02:53 +02:00
import java.util.Properties;
import java.io.File;
2016-06-01 11:41:50 +03:00
import com.lwansbrough.RCTCamera.*;
2016-03-23 17:02:53 +02:00
import com.i18n.reactnativei18n.ReactNativeI18n;
import io.realm.react.RealmReactPackage;
2016-03-23 16:48:26 +02:00
2016-06-01 11:41:50 +03:00
2016-03-23 16:48:26 +02:00
public class MainActivity extends ReactActivity {
2016-06-16 07:23:11 +03:00
/**
* Incoming message handler. Calls to its binder are sequential!
*/
protected final IncomingHandler handler = new IncomingHandler();
/** Flag indicating if the service is bound. */
protected boolean isBound;
/** Sends messages to the service. */
protected Messenger serviceMessenger = null;
/** Receives messages from the service. */
protected Messenger clientMessenger = new Messenger(handler);
class IncomingHandler extends Handler {
@Override
public void handleMessage(Message message) {
boolean isClaimed = false;
System.out.println("!!!!!!!!!!!!!! Received Service Message !!!!!!!!!!!!!!");
super.handleMessage(message);
}
}
protected ServiceConnection serviceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
// This is called when the connection with the service has been
// established, giving us the object we can use to
// interact with the service. We are communicating with the
// service using a Messenger, so here we get a client-side
// representation of that from the raw IBinder object.
serviceMessenger = new Messenger(service);
isBound = true;
onConnected();
}
public void onServiceDisconnected(ComponentName className) {
// This is called when the connection with the service has been
// unexpectedly disconnected -- that is, its process crashed.
serviceMessenger = null;
isBound = false;
System.out.println("!!!!!!!!!!!!!! Geth Service Disconnected !!!!!!!!!!!!!!");
}
};
protected void onConnected() {
System.out.println("!!!!!!!!!!!!!! Geth Service Connected !!!!!!!!!!!!!!");
}
2016-03-23 17:02:53 +02:00
2016-06-08 12:43:02 +02:00
protected void startStatus() {
// Required because of crazy APN settings redirecting localhost (found in GB)
2016-03-23 17:02:53 +02:00
Properties properties = System.getProperties();
properties.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");
properties.setProperty("https.nonProxyHosts", "localhost|127.0.0.1");
}
2016-06-08 12:43:02 +02:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!RootUtil.isDeviceRooted()) {
startStatus();
} else {
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setMessage(getResources().getString(R.string.root_warning))
.setPositiveButton(getResources().getString(R.string.root_okay), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
startStatus();
}
}).setNegativeButton(getResources().getString(R.string.root_cancel), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
MainActivity.this.finishAffinity();
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
MainActivity.this.finishAffinity();
}
}).create();
dialog.show();
}
2016-06-16 07:23:11 +03:00
Intent intent = new Intent(this, GethService.class);
if (!GethService.isRunning()) {
startService(intent);
}
if (serviceConnection != null && GethService.isRunning()) {
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}
2016-06-08 12:43:02 +02:00
2016-03-23 17:02:53 +02:00
}
2016-06-16 07:23:11 +03:00
@Override
protected void onDestroy() {
super.onDestroy();
try {
unbindService(serviceConnection);
}
catch (Throwable t) {
Log.e("MainActivity", "Failed to unbind from the geth service", t);
}
}
2016-03-23 16:48:26 +02:00
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
2016-05-19 18:32:38 +02:00
return "StatusIm";
2016-03-23 16:48:26 +02:00
}
/**
* Returns whether dev mode should be enabled.
* This enables e.g. the dev menu.
*/
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
2016-04-01 18:05:55 +03:00
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
2016-03-23 16:48:26 +02:00
@Override
protected List<ReactPackage> getPackages() {
2016-03-23 17:02:53 +02:00
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
2016-04-01 18:05:55 +03:00
new RealmReactPackage(),
new VectorIconsPackage(),
2016-03-23 17:02:53 +02:00
new ReactNativeContacts(),
new ReactNativeI18n(),
2016-05-18 17:40:26 +03:00
new RandomBytesPackage(),
new LinearGradientPackage(),
2016-06-01 11:41:50 +03:00
new RCTCameraPackage(),
2016-05-18 17:40:26 +03:00
new SmsListener(this)
2016-03-23 17:02:53 +02:00
);
2016-03-23 16:48:26 +02:00
}
}