forked from jens/Automation
started to adapt tethering trigger to check a specific type
This commit is contained in:
@ -9,11 +9,19 @@ import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageTriggerTethering extends Activity
|
||||
{
|
||||
RadioButton rbTetheringOn, rbTetheringOff;
|
||||
RadioButton rbTetheringOn, rbTetheringOff, rbTetheringTypeAny, rbTetheringTypeWifi, rbTetheringTypeBluetooth, rbTetheringTypeUsb, rbTetheringTypeCable;
|
||||
Button bTriggerTetheringSave;
|
||||
|
||||
public final static String tetheringTypeAny = "tetheringTypeAny";
|
||||
public final static String tetheringTypeWifi = "tetheringTypeWifi";
|
||||
public final static String tetheringTypeBluetooth = "tetheringTypeBluetooth";
|
||||
public final static String tetheringTypeUsb = "tetheringTypeUsb";
|
||||
public final static String tetheringTypeCable = "tetheringTypeCable";
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
@ -22,6 +30,11 @@ public class ActivityManageTriggerTethering extends Activity
|
||||
|
||||
rbTetheringOn = (RadioButton) findViewById(R.id.rbTetheringOn);
|
||||
rbTetheringOff = (RadioButton)findViewById(R.id.rbTetheringOff);
|
||||
rbTetheringTypeAny = (RadioButton) findViewById(R.id.rbTetheringTypeAny);
|
||||
rbTetheringTypeWifi = (RadioButton) findViewById(R.id.rbTetheringTypeWifi);
|
||||
rbTetheringTypeBluetooth = (RadioButton) findViewById(R.id.rbTetheringTypeBluetooth);
|
||||
rbTetheringTypeUsb = (RadioButton) findViewById(R.id.rbTetheringTypeUsb);
|
||||
rbTetheringTypeCable = (RadioButton) findViewById(R.id.rbTetheringTypeCable);
|
||||
bTriggerTetheringSave = (Button) findViewById(R.id.bTriggerTetheringSave);
|
||||
|
||||
Intent input = getIntent();
|
||||
@ -31,6 +44,31 @@ public class ActivityManageTriggerTethering extends Activity
|
||||
rbTetheringOff.setChecked(!input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, false));
|
||||
}
|
||||
|
||||
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
String type = input.getStringExtra(ActivityManageRule.intentNameTriggerParameter2);
|
||||
|
||||
if(!StringUtils.isEmpty(type))
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case tetheringTypeAny:
|
||||
rbTetheringTypeAny.setChecked(true);
|
||||
case tetheringTypeWifi:
|
||||
rbTetheringTypeWifi.setChecked(true);
|
||||
case tetheringTypeBluetooth:
|
||||
rbTetheringTypeBluetooth.setChecked(true);
|
||||
case tetheringTypeUsb:
|
||||
rbTetheringTypeUsb.setChecked(true);
|
||||
case tetheringTypeCable:
|
||||
rbTetheringTypeCable.setChecked(true);
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
rbTetheringTypeAny.setChecked(true);
|
||||
|
||||
bTriggerTetheringSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
@ -38,6 +76,18 @@ public class ActivityManageTriggerTethering extends Activity
|
||||
{
|
||||
Intent response = new Intent();
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbTetheringOn.isChecked());
|
||||
|
||||
if(rbTetheringTypeAny.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeAny);
|
||||
else if(rbTetheringTypeWifi.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeWifi);
|
||||
else if(rbTetheringTypeBluetooth.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeBluetooth);
|
||||
else if(rbTetheringTypeUsb.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeUsb);
|
||||
else if(rbTetheringTypeCable.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeCable);
|
||||
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
|
49
app/src/main/java/com/jens/automation2/MainActivityTabs.java
Normal file
49
app/src/main/java/com/jens/automation2/MainActivityTabs.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.jens.automation2.ui.main.SectionsPagerAdapter;
|
||||
import com.jens.automation2.databinding.ActivityMainTabsBinding;
|
||||
|
||||
public class MainActivityTabs extends AppCompatActivity
|
||||
{
|
||||
|
||||
private ActivityMainTabsBinding binding;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
binding = ActivityMainTabsBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
|
||||
ViewPager viewPager = binding.viewPager;
|
||||
viewPager.setAdapter(sectionsPagerAdapter);
|
||||
TabLayout tabs = binding.tabs;
|
||||
tabs.setupWithViewPager(viewPager);
|
||||
FloatingActionButton fab = binding.fab;
|
||||
|
||||
fab.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.jens.automation2.ui.main;
|
||||
|
||||
import androidx.arch.core.util.Function;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Transformations;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class PageViewModel extends ViewModel
|
||||
{
|
||||
|
||||
private MutableLiveData<Integer> mIndex = new MutableLiveData<>();
|
||||
private LiveData<String> mText = Transformations.map(mIndex, new Function<Integer, String>()
|
||||
{
|
||||
@Override
|
||||
public String apply(Integer input)
|
||||
{
|
||||
return "Hello world from section: " + input;
|
||||
}
|
||||
});
|
||||
|
||||
public void setIndex(int index)
|
||||
{
|
||||
mIndex.setValue(index);
|
||||
}
|
||||
|
||||
public LiveData<String> getText()
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.jens.automation2.ui.main;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.jens.automation2.R;
|
||||
import com.jens.automation2.databinding.FragmentMainActivityTabsBinding;
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public class PlaceholderFragment extends Fragment
|
||||
{
|
||||
|
||||
private static final String ARG_SECTION_NUMBER = "section_number";
|
||||
|
||||
private PageViewModel pageViewModel;
|
||||
private FragmentMainActivityTabsBinding binding;
|
||||
|
||||
public static PlaceholderFragment newInstance(int index)
|
||||
{
|
||||
PlaceholderFragment fragment = new PlaceholderFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(ARG_SECTION_NUMBER, index);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
pageViewModel = new ViewModelProvider(this).get(PageViewModel.class);
|
||||
int index = 1;
|
||||
if (getArguments() != null)
|
||||
{
|
||||
index = getArguments().getInt(ARG_SECTION_NUMBER);
|
||||
}
|
||||
pageViewModel.setIndex(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState)
|
||||
{
|
||||
|
||||
binding = FragmentMainActivityTabsBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.sectionLabel;
|
||||
pageViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>()
|
||||
{
|
||||
@Override
|
||||
public void onChanged(@Nullable String s)
|
||||
{
|
||||
textView.setText(s);
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.jens.automation2.ui.main;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
|
||||
import com.jens.automation2.R;
|
||||
|
||||
/**
|
||||
* A [FragmentPagerAdapter] that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends FragmentPagerAdapter
|
||||
{
|
||||
|
||||
@StringRes
|
||||
private static final int[] TAB_TITLES = new int[]{R.string.tab_text_1, R.string.tab_text_2};
|
||||
private final Context mContext;
|
||||
|
||||
public SectionsPagerAdapter(Context context, FragmentManager fm)
|
||||
{
|
||||
super(fm);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position)
|
||||
{
|
||||
// getItem is called to instantiate the fragment for the given page.
|
||||
// Return a PlaceholderFragment (defined as a static inner class below).
|
||||
return PlaceholderFragment.newInstance(position + 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position)
|
||||
{
|
||||
return mContext.getResources().getString(TAB_TITLES[position]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
// Show 2 total pages.
|
||||
return 2;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user