|
|
@@ -12,6 +12,8 @@ import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.BaseAdapter;
|
|
|
+import android.widget.BaseExpandableListAdapter;
|
|
|
+import android.widget.ExpandableListView;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
@@ -28,16 +30,20 @@ import java.util.ArrayList;
|
|
|
|
|
|
public class OptionActivity extends BasicActivity {
|
|
|
|
|
|
+ private static final String OptionTitleKey = "OptionTitle";
|
|
|
private static final String OptionsKey = "OptionsKey";
|
|
|
public static final String SelectedKey = "SelectedKey";
|
|
|
private static final String SelectedIndexKey = "SelectedIndexKey";
|
|
|
|
|
|
- public static void startOptionActivity(Activity activity, String optionsJson, int selectedOption, int requestCode) {
|
|
|
+ public static void startOptionActivity(Activity activity, String optionTitle, String optionsJson, int selectedOption, int requestCode) {
|
|
|
if (activity == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Intent intent = new Intent(activity,OptionActivity.class);
|
|
|
+ if (optionTitle != null) {
|
|
|
+ intent.putExtra(OptionTitleKey,optionTitle);
|
|
|
+ }
|
|
|
if (optionsJson != null) {
|
|
|
intent.putExtra(OptionsKey,optionsJson);
|
|
|
}
|
|
|
@@ -49,11 +55,12 @@ public class OptionActivity extends BasicActivity {
|
|
|
private Context mCtx = this;
|
|
|
private String optionsJson;
|
|
|
private int selectedOption;
|
|
|
+ private String title;
|
|
|
|
|
|
private ArrayList<SettingOption> options = new ArrayList<>();
|
|
|
private int selectedIndex = -1;
|
|
|
|
|
|
- private ListView mListView;
|
|
|
+ private ExpandableListView mListView;
|
|
|
private OptionAdapter mAdapter;
|
|
|
|
|
|
@Override
|
|
|
@@ -71,12 +78,14 @@ public class OptionActivity extends BasicActivity {
|
|
|
|
|
|
optionsJson = savedInstanceState.getString(OptionsKey);
|
|
|
selectedIndex = savedInstanceState.getInt(SelectedIndexKey);
|
|
|
+ title = savedInstanceState.getString(OptionTitleKey);
|
|
|
|
|
|
} else {
|
|
|
if (getIntent() != null) {
|
|
|
|
|
|
optionsJson = getIntent().getStringExtra(OptionsKey);
|
|
|
selectedOption = getIntent().getIntExtra(SelectedKey,-1);
|
|
|
+ title = getIntent().getStringExtra(OptionTitleKey);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -109,17 +118,30 @@ public class OptionActivity extends BasicActivity {
|
|
|
mAdapter = new OptionAdapter();
|
|
|
mListView = findViewById(R.id.option_list_view);
|
|
|
mListView.setAdapter(mAdapter);
|
|
|
- mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
|
|
@Override
|
|
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
|
|
|
|
|
- if (position != selectedIndex) {
|
|
|
- selectedIndex = position;
|
|
|
+ if (childPosition != selectedIndex) {
|
|
|
+ selectedIndex = childPosition;
|
|
|
mAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
|
|
|
+ return true;
|
|
|
}
|
|
|
});
|
|
|
+ mListView.setGroupIndicator(null);
|
|
|
+
|
|
|
+ int groupCount = mAdapter.getGroupCount();
|
|
|
+ for (int i = 0; i < groupCount; i++) {
|
|
|
+ mListView.expandGroup(i);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -131,6 +153,9 @@ public class OptionActivity extends BasicActivity {
|
|
|
if (optionsJson != null) {
|
|
|
outState.putString(OptionsKey,optionsJson);
|
|
|
}
|
|
|
+ if (title != null) {
|
|
|
+ outState.putString(OptionTitleKey,title);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -162,25 +187,64 @@ public class OptionActivity extends BasicActivity {
|
|
|
super.finish();
|
|
|
}
|
|
|
|
|
|
- private class OptionAdapter extends BaseAdapter {
|
|
|
+ private class OptionAdapter extends BaseExpandableListAdapter {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getGroupCount() {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public int getCount() {
|
|
|
+ public int getChildrenCount(int groupPosition) {
|
|
|
return options.size();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object getItem(int position) {
|
|
|
- return options.get(position);
|
|
|
+ public Object getGroup(int groupPosition) {
|
|
|
+ return options;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public long getItemId(int position) {
|
|
|
- return position;
|
|
|
+ public Object getChild(int groupPosition, int childPosition) {
|
|
|
+ return options.get(childPosition);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
+ public long getGroupId(int groupPosition) {
|
|
|
+ return groupPosition;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getChildId(int groupPosition, int childPosition) {
|
|
|
+ return childPosition;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean hasStableIds() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
|
|
|
+
|
|
|
+ HeaderHolder holder;
|
|
|
+ if (convertView == null) {
|
|
|
+
|
|
|
+ convertView = LayoutInflater.from(mCtx).inflate(R.layout.option_group_header,null);
|
|
|
+ holder = new HeaderHolder(convertView);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ holder = (HeaderHolder)convertView.getTag();
|
|
|
+ }
|
|
|
+
|
|
|
+ holder.titleTv.setText(title);
|
|
|
+
|
|
|
+ return convertView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
|
|
|
|
|
Holder holder;
|
|
|
if (convertView == null) {
|
|
|
@@ -193,11 +257,26 @@ public class OptionActivity extends BasicActivity {
|
|
|
holder = (Holder)convertView.getTag();
|
|
|
}
|
|
|
|
|
|
- SettingOption option = options.get(position);
|
|
|
- holder.setModel(option,position);
|
|
|
+ SettingOption option = options.get(childPosition);
|
|
|
+ holder.setModel(option,childPosition);
|
|
|
|
|
|
return convertView;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isChildSelectable(int groupPosition, int childPosition) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private class HeaderHolder {
|
|
|
+ TextView titleTv;
|
|
|
+
|
|
|
+ HeaderHolder(View view) {
|
|
|
+ view.setTag(this);
|
|
|
+
|
|
|
+ titleTv = view.findViewById(R.id.option_group_header_title_tv);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private class Holder {
|