forked from jens/Automation
profile trigger
parent
8c6331237d
commit
5653a9c70e
@ -0,0 +1,116 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ActivityManageTriggerProfile extends Activity
|
||||
{
|
||||
public static final String profileFieldName = "profileName";
|
||||
|
||||
boolean editMode = false;
|
||||
|
||||
Button bSaveTriggerProfile;
|
||||
Spinner spinnerProfiles;
|
||||
CheckBox chkProfileActive, chkProfileCheckSettings;
|
||||
|
||||
ArrayAdapter<Profile> profileSpinnerAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manage_trigger_profile);
|
||||
|
||||
bSaveTriggerProfile = (Button)findViewById(R.id.bSaveTriggerProfile);
|
||||
spinnerProfiles = (Spinner)findViewById(R.id.spinnerProfiles);
|
||||
chkProfileActive = (CheckBox)findViewById(R.id.chkProfileActive);
|
||||
chkProfileCheckSettings = (CheckBox)findViewById(R.id.chkProfileCheckSettings);
|
||||
|
||||
try
|
||||
{
|
||||
profileSpinnerAdapter = new ArrayAdapter<Profile>(this, R.layout.text_view_for_poi_listview_mediumtextsize, Profile.getProfileCollection());
|
||||
loadProfileItems();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "ActivityManageTriggerProfile", Log.getStackTraceString(e), 1);
|
||||
}
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
editMode = true;
|
||||
try
|
||||
{
|
||||
String values[] = getIntent().getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
|
||||
if(values.length >= 2)
|
||||
{
|
||||
boolean active = getIntent().getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true);
|
||||
chkProfileActive.setChecked(active);
|
||||
|
||||
boolean checkSettings = Boolean.parseBoolean(values[0]);
|
||||
chkProfileCheckSettings.setChecked(checkSettings);
|
||||
|
||||
String profileName = values[1];
|
||||
|
||||
List<Profile> profileList = Profile.getProfileCollection();
|
||||
for(int i = 0; i < profileList.size(); i++)
|
||||
{
|
||||
if(profileList.get(i).getName().equals(profileName))
|
||||
{
|
||||
spinnerProfiles.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Toast.makeText(ActivityManageTriggerProfile.this, getResources().getString(R.string.triggerWrong), Toast.LENGTH_SHORT).show();
|
||||
Miscellaneous.logEvent("e", "ActivityManageTriggerProfile", "There\'s something wrong with parameters. Content: " + getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2) + ", " + Log.getStackTraceString(e), 1);
|
||||
}
|
||||
}
|
||||
|
||||
bSaveTriggerProfile.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent returnData = new Intent();
|
||||
returnData.putExtra(ActivityManageRule.intentNameTriggerParameter1, chkProfileActive.isChecked());
|
||||
returnData.putExtra(ActivityManageRule.intentNameTriggerParameter2,
|
||||
spinnerProfiles.getSelectedItem().toString() + Trigger.triggerParameter2Split +
|
||||
chkProfileCheckSettings.isChecked());
|
||||
|
||||
setResult(RESULT_OK, returnData);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadProfileItems()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(spinnerProfiles.getAdapter() == null)
|
||||
spinnerProfiles.setAdapter(profileSpinnerAdapter);
|
||||
|
||||
profileSpinnerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
catch(NullPointerException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="@dimen/default_margin"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:shrinkColumns="1"
|
||||
android:stretchColumns="1" >
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:text="@string/profile"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinnerProfiles"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:text="@string/needsToBeActive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/chkProfileActive"
|
||||
android:checked="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:text="@string/checkSettings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/chkProfileCheckSettings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/bSaveTriggerProfile"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/default_margin"
|
||||
android:text="@string/save" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
@ -1 +1,2 @@
|
||||
* Exclusion from battery optimization
|
||||
* Exclusion from battery optimization
|
||||
* Profiles can be used as trigger
|
Loading…
Reference in New Issue