mirror of
https://github.com/tijder/SmsMatrix.git
synced 2024-10-27 18:24:01 +00:00
Merge branch 'master' of https://github.com/tijder/SmsMatrix
This commit is contained in:
commit
50b0a1565f
@ -1,9 +1,11 @@
|
|||||||
package eu.droogers.smsmatrix;
|
package eu.droogers.smsmatrix;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -20,11 +22,14 @@ public class MainActivity extends Activity {
|
|||||||
private EditText username;
|
private EditText username;
|
||||||
private EditText device;
|
private EditText device;
|
||||||
private EditText hsUrl;
|
private EditText hsUrl;
|
||||||
|
private EditText syncDelay;
|
||||||
|
private EditText syncTimeout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
checkPermissions();
|
||||||
|
|
||||||
sp = getSharedPreferences("settings", Context.MODE_PRIVATE);
|
sp = getSharedPreferences("settings", Context.MODE_PRIVATE);
|
||||||
botUsername = (EditText) findViewById(R.id.editText_botUsername);
|
botUsername = (EditText) findViewById(R.id.editText_botUsername);
|
||||||
@ -32,24 +37,31 @@ public class MainActivity extends Activity {
|
|||||||
username = (EditText) findViewById(R.id.editText_username);
|
username = (EditText) findViewById(R.id.editText_username);
|
||||||
device = (EditText) findViewById(R.id.editText_device);
|
device = (EditText) findViewById(R.id.editText_device);
|
||||||
hsUrl = (EditText) findViewById(R.id.editText_hsUrl);
|
hsUrl = (EditText) findViewById(R.id.editText_hsUrl);
|
||||||
|
syncDelay = (EditText) findViewById(R.id.editText_syncDelay);
|
||||||
|
syncTimeout = (EditText) findViewById(R.id.editText_syncTimeout);
|
||||||
|
|
||||||
botUsername.setText(sp.getString("botUsername", ""));
|
botUsername.setText(sp.getString("botUsername", ""));
|
||||||
botPassword.setText(sp.getString("botPassword", ""));
|
botPassword.setText(sp.getString("botPassword", ""));
|
||||||
username.setText(sp.getString("username", ""));
|
username.setText(sp.getString("username", ""));
|
||||||
device.setText(sp.getString("device", ""));
|
device.setText(sp.getString("device", ""));
|
||||||
hsUrl.setText(sp.getString("hsUrl", ""));
|
hsUrl.setText(sp.getString("hsUrl", ""));
|
||||||
|
syncDelay.setText(sp.getString("syncDelay", ""));
|
||||||
|
syncTimeout.setText(sp.getString("syncTimeout", ""));
|
||||||
|
|
||||||
|
|
||||||
Button saveButton = (Button) findViewById(R.id.button_save);
|
Button saveButton = (Button) findViewById(R.id.button_save);
|
||||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
checkPermissions();
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
editor.putString("botUsername", botUsername.getText().toString());
|
editor.putString("botUsername", botUsername.getText().toString());
|
||||||
editor.putString("botPassword", botPassword.getText().toString());
|
editor.putString("botPassword", botPassword.getText().toString());
|
||||||
editor.putString("username", username.getText().toString());
|
editor.putString("username", username.getText().toString());
|
||||||
editor.putString("device", device.getText().toString());
|
editor.putString("device", device.getText().toString());
|
||||||
editor.putString("hsUrl", hsUrl.getText().toString());
|
editor.putString("hsUrl", hsUrl.getText().toString());
|
||||||
|
editor.putString("syncDelay", syncDelay.getText().toString());
|
||||||
|
editor.putString("syncTimeout", syncTimeout.getText().toString());
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
|
||||||
Log.e(TAG, "onClick: " + botUsername.getText().toString() );
|
Log.e(TAG, "onClick: " + botUsername.getText().toString() );
|
||||||
@ -59,6 +71,20 @@ public class MainActivity extends Activity {
|
|||||||
startService();
|
startService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkPermissions() {
|
||||||
|
askPermission(Manifest.permission.SEND_SMS);
|
||||||
|
askPermission(Manifest.permission.READ_PHONE_STATE);
|
||||||
|
askPermission(Manifest.permission.READ_CONTACTS);
|
||||||
|
askPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void askPermission(String permission) {
|
||||||
|
if (getApplicationContext().checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
this.requestPermissions(new String[]{permission},1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void startService() {
|
private void startService() {
|
||||||
Intent intent = new Intent(this, MatrixService.class);
|
Intent intent = new Intent(this, MatrixService.class);
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
@ -41,6 +41,8 @@ import static android.content.ContentValues.TAG;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class Matrix {
|
public class Matrix {
|
||||||
|
private final int syncDelay;
|
||||||
|
private final int syncTimeout;
|
||||||
HomeServerConnectionConfig hsConfig;
|
HomeServerConnectionConfig hsConfig;
|
||||||
Context context;
|
Context context;
|
||||||
MXSession session;
|
MXSession session;
|
||||||
@ -56,7 +58,7 @@ public class Matrix {
|
|||||||
|
|
||||||
private String realUserid;
|
private String realUserid;
|
||||||
|
|
||||||
public Matrix (final Context context, String url, String botUsername, String botPassword, String username, String device) {
|
public Matrix(final Context context, String url, String botUsername, String botPassword, String username, String device, String syncDelay, String syncTimeout) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
hsConfig = new HomeServerConnectionConfig(Uri.parse(url));
|
hsConfig = new HomeServerConnectionConfig(Uri.parse(url));
|
||||||
|
|
||||||
@ -64,6 +66,8 @@ public class Matrix {
|
|||||||
deviceName = device;
|
deviceName = device;
|
||||||
this.botUsername = botUsername;
|
this.botUsername = botUsername;
|
||||||
botHSUrl = url;
|
botHSUrl = url;
|
||||||
|
this.syncDelay = Integer.parseInt(syncDelay);
|
||||||
|
this.syncTimeout = Integer.parseInt(syncTimeout);
|
||||||
|
|
||||||
login(botUsername, botPassword);
|
login(botUsername, botPassword);
|
||||||
}
|
}
|
||||||
@ -99,8 +103,8 @@ public class Matrix {
|
|||||||
// NetworkConnectivityReceiver nwMan = new NetworkConnectivityReceiver();
|
// NetworkConnectivityReceiver nwMan = new NetworkConnectivityReceiver();
|
||||||
|
|
||||||
session = new MXSession(hsConfig, dh, context);
|
session = new MXSession(hsConfig, dh, context);
|
||||||
session.setSyncDelay(12000);
|
session.setSyncDelay(syncDelay * 1000);
|
||||||
session.setSyncTimeout(30*60*1000);
|
session.setSyncTimeout(syncTimeout * 60 * 1000);
|
||||||
Log.e(TAG, "onLogin:" + session.getSyncTimeout());
|
Log.e(TAG, "onLogin:" + session.getSyncTimeout());
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ public class MatrixService extends Service {
|
|||||||
private String username;
|
private String username;
|
||||||
private String device;
|
private String device;
|
||||||
private String hsUrl;
|
private String hsUrl;
|
||||||
|
private String syncDelay;
|
||||||
|
private String syncTimeout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -35,9 +37,11 @@ public class MatrixService extends Service {
|
|||||||
username = sp.getString("username", "");
|
username = sp.getString("username", "");
|
||||||
device = sp.getString("device", "");
|
device = sp.getString("device", "");
|
||||||
hsUrl = sp.getString("hsUrl", "");
|
hsUrl = sp.getString("hsUrl", "");
|
||||||
|
syncDelay = sp.getString("syncDelay", "");
|
||||||
|
syncTimeout = sp.getString("syncTimeout", "");
|
||||||
|
|
||||||
if (mx == null && !botUsername.isEmpty() && !botPassword.isEmpty() && !username.isEmpty() && !device.isEmpty() && !hsUrl.isEmpty()) {
|
if (mx == null && !botUsername.isEmpty() && !botPassword.isEmpty() && !username.isEmpty() && !device.isEmpty() && !hsUrl.isEmpty() && !syncDelay.isEmpty() && !syncTimeout.isEmpty()) {
|
||||||
mx = new Matrix(getApplication(), hsUrl, botUsername, botPassword, username, device);
|
mx = new Matrix(getApplication(), hsUrl, botUsername, botPassword, username, device, syncDelay, syncTimeout);
|
||||||
Log.e(TAG, "onStartCommand222: " + hsUrl );
|
Log.e(TAG, "onStartCommand222: " + hsUrl );
|
||||||
Toast.makeText(this, "service starting:", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "service starting:", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,40 @@
|
|||||||
android:hint="Sms_mobiel"
|
android:hint="Sms_mobiel"
|
||||||
android:inputType="textPersonName" />
|
android:inputType="textPersonName" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_syncDelay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="SyncDelay in seconds"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editText_syncDelay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="12"
|
||||||
|
android:inputType="number" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_syncTimeout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="SyncTimeout in minutes"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editText_syncTimeout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="30"
|
||||||
|
android:inputType="number" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button_save"
|
android:id="@+id/button_save"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user