2021-02-16 13:42:49 +01:00
|
|
|
package com.jens.automation2;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemLongClickListener;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TableLayout;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.jens.automation2.Action.Action_Enum;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
2021-03-29 16:36:21 +02:00
|
|
|
public class ActivityManageActionTriggerUrl extends Activity
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
Button bSaveTriggerUrl;
|
|
|
|
EditText etTriggerUrl, etTriggerUrlUsername, etTriggerUrlPassword;
|
|
|
|
ListView lvTriggerUrlPostParameters;
|
|
|
|
CheckBox chkTriggerUrlUseAuthentication;
|
|
|
|
TableLayout tlTriggerUrlAuthentication;
|
|
|
|
|
|
|
|
ArrayAdapter<Map<String,String>> lvTriggerUrlPostParametersAdapter;
|
|
|
|
|
|
|
|
// private String existingUrl = "";
|
|
|
|
|
|
|
|
public static boolean edit = false;
|
|
|
|
public static Action resultingAction = null;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
2021-05-30 20:03:30 +02:00
|
|
|
this.setContentView(R.layout.activity_manage_action_trigger_url);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
etTriggerUrl = (EditText)findViewById(R.id.etTriggerUrl);
|
|
|
|
etTriggerUrlUsername = (EditText)findViewById(R.id.etTriggerUrlUsername);
|
|
|
|
etTriggerUrlPassword = (EditText)findViewById(R.id.etTriggerUrlPassword);
|
|
|
|
chkTriggerUrlUseAuthentication = (CheckBox)findViewById(R.id.chkTriggerUrlUseAuthentication);
|
|
|
|
lvTriggerUrlPostParameters = (ListView)findViewById(R.id.lvTriggerUrlPostParameters);
|
|
|
|
tlTriggerUrlAuthentication = (TableLayout)findViewById(R.id.tlTriggerUrlAuthentication);
|
|
|
|
bSaveTriggerUrl = (Button)findViewById(R.id.bSaveTriggerUrl);
|
|
|
|
bSaveTriggerUrl.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
if(etTriggerUrl.getText().toString().length() > 0)
|
|
|
|
{
|
|
|
|
if(resultingAction == null)
|
|
|
|
{
|
|
|
|
resultingAction = new Action();
|
|
|
|
resultingAction.setAction(Action_Enum.triggerUrl);
|
|
|
|
resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked());
|
|
|
|
|
|
|
|
String username = etTriggerUrlUsername.getText().toString();
|
|
|
|
String password = etTriggerUrlPassword.getText().toString();
|
|
|
|
|
|
|
|
if(username == null)
|
|
|
|
username = "";
|
|
|
|
|
|
|
|
if(password == null)
|
|
|
|
password = "";
|
|
|
|
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionTriggerUrl.resultingAction.setParameter2(
|
2021-02-16 13:42:49 +01:00
|
|
|
username + ";" +
|
|
|
|
password + ";" +
|
|
|
|
etTriggerUrl.getText().toString().trim()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
backToRuleManager();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Toast.makeText(getBaseContext(), getResources().getString(R.string.urlTooShort), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
chkTriggerUrlUseAuthentication.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
|
|
{
|
|
|
|
if(isChecked)
|
|
|
|
tlTriggerUrlAuthentication.setVisibility(View.VISIBLE);
|
|
|
|
else
|
|
|
|
tlTriggerUrlAuthentication.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
etTriggerUrlUsername.setEnabled(isChecked);
|
|
|
|
etTriggerUrlPassword.setEnabled(isChecked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
lvTriggerUrlPostParameters.setOnItemLongClickListener(new OnItemLongClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
updateListView();
|
|
|
|
|
|
|
|
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionTriggerUrl.edit = getIntent().getBooleanExtra("edit", false);
|
2021-02-16 13:42:49 +01:00
|
|
|
if(edit)
|
|
|
|
{
|
|
|
|
// username,password,URL
|
2021-03-29 16:36:21 +02:00
|
|
|
String[] components = ActivityManageActionTriggerUrl.resultingAction.getParameter2().split(";");
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
if(components.length >= 3)
|
|
|
|
{
|
|
|
|
etTriggerUrl.setText(components[2]);
|
2021-03-29 16:36:21 +02:00
|
|
|
chkTriggerUrlUseAuthentication.setChecked(ActivityManageActionTriggerUrl.resultingAction.getParameter1());
|
2021-02-16 13:42:49 +01:00
|
|
|
etTriggerUrlUsername.setText(components[0]);
|
|
|
|
etTriggerUrlPassword.setText(components[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
etTriggerUrl.setText(components[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void backToRuleManager()
|
|
|
|
{
|
|
|
|
if(edit && resultingAction != null)
|
|
|
|
{
|
|
|
|
String username = etTriggerUrlUsername.getText().toString();
|
|
|
|
String password = etTriggerUrlPassword.getText().toString();
|
|
|
|
|
|
|
|
if(username == null)
|
|
|
|
username = "";
|
|
|
|
|
|
|
|
if(password == null)
|
|
|
|
password = "";
|
|
|
|
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionTriggerUrl.resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked());
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionTriggerUrl.resultingAction.setParameter2(
|
2021-02-16 13:42:49 +01:00
|
|
|
username + ";" +
|
|
|
|
password + ";" +
|
|
|
|
etTriggerUrl.getText().toString()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
|
|
|
|
this.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateListView()
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("i", "ListView", "Attempting to update lvTriggerUrlPostParameters", 4);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(lvTriggerUrlPostParameters.getAdapter() == null)
|
|
|
|
lvTriggerUrlPostParameters.setAdapter(lvTriggerUrlPostParametersAdapter);
|
|
|
|
|
|
|
|
lvTriggerUrlPostParametersAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
catch(NullPointerException e)
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
}
|