diff --git a/f2/.gitignore b/lab2/.gitignore similarity index 100% rename from f2/.gitignore rename to lab2/.gitignore diff --git a/f2/.idea/.gitignore b/lab2/.idea/.gitignore similarity index 100% rename from f2/.idea/.gitignore rename to lab2/.idea/.gitignore diff --git a/f2/.idea/.name b/lab2/.idea/.name similarity index 100% rename from f2/.idea/.name rename to lab2/.idea/.name diff --git a/f2/.idea/compiler.xml b/lab2/.idea/compiler.xml similarity index 100% rename from f2/.idea/compiler.xml rename to lab2/.idea/compiler.xml diff --git a/f2/.idea/deploymentTargetDropDown.xml b/lab2/.idea/deploymentTargetDropDown.xml similarity index 100% rename from f2/.idea/deploymentTargetDropDown.xml rename to lab2/.idea/deploymentTargetDropDown.xml diff --git a/f2/.idea/gradle.xml b/lab2/.idea/gradle.xml similarity index 100% rename from f2/.idea/gradle.xml rename to lab2/.idea/gradle.xml diff --git a/f2/.idea/misc.xml b/lab2/.idea/misc.xml similarity index 100% rename from f2/.idea/misc.xml rename to lab2/.idea/misc.xml diff --git a/f2/.idea/vcs.xml b/lab2/.idea/vcs.xml similarity index 100% rename from f2/.idea/vcs.xml rename to lab2/.idea/vcs.xml diff --git a/f2/app/.gitignore b/lab2/app/.gitignore similarity index 100% rename from f2/app/.gitignore rename to lab2/app/.gitignore diff --git a/f2/app/build.gradle b/lab2/app/build.gradle similarity index 100% rename from f2/app/build.gradle rename to lab2/app/build.gradle diff --git a/f2/app/proguard-rules.pro b/lab2/app/proguard-rules.pro similarity index 100% rename from f2/app/proguard-rules.pro rename to lab2/app/proguard-rules.pro diff --git a/f2/app/src/androidTest/java/com/example/f2/ExampleInstrumentedTest.java b/lab2/app/src/androidTest/java/com/example/f2/ExampleInstrumentedTest.java similarity index 100% rename from f2/app/src/androidTest/java/com/example/f2/ExampleInstrumentedTest.java rename to lab2/app/src/androidTest/java/com/example/f2/ExampleInstrumentedTest.java diff --git a/f2/app/src/main/AndroidManifest.xml b/lab2/app/src/main/AndroidManifest.xml similarity index 100% rename from f2/app/src/main/AndroidManifest.xml rename to lab2/app/src/main/AndroidManifest.xml diff --git a/f2/app/src/main/java/com/example/f2/MainActivity.java b/lab2/app/src/main/java/com/example/f2/MainActivity.java similarity index 54% rename from f2/app/src/main/java/com/example/f2/MainActivity.java rename to lab2/app/src/main/java/com/example/f2/MainActivity.java index 82f90a03c68fb191cb27a1e949096f119134e437..3124fc1cc4a97eb49389870c71c1770bf0b5403d 100644 --- a/f2/app/src/main/java/com/example/f2/MainActivity.java +++ b/lab2/app/src/main/java/com/example/f2/MainActivity.java @@ -38,34 +38,19 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ExpandableListView listView = findViewById(R.id.listView); - HashMap<String,List<String>> data = getData(); + HashMap<String, List<String>> data = getData(); ArrayList<String> list = new ArrayList<String>(data.keySet()); - adapter = new TestAdapter(this,list,data); + adapter = new TestAdapter(this, list, data); listView.setAdapter(adapter); - -// listView.setSelectedChild(1,1,true); - - listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - String text = "/" + (String) adapter.getGroup(groupPosition) + "/" + (String) adapter.getChild(groupPosition, childPosition); - adapter.select(groupPosition,childPosition); - listView.setVisibility(View.GONE); - listView.setVisibility(View.VISIBLE); - -// v.setBackgroundColor(Color.GRAY); - - - v.requestLayout(); -// listView.requestLayout(); - parent.postInvalidate(); - select(text); - - return true; - } - }); + @Override + public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { + String text = "/" + (String) adapter.getGroup(groupPosition) + "/" + (String) adapter.getChild(groupPosition, childPosition); + select(text); + return true; + } + }); // listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override @@ -90,84 +75,57 @@ public class MainActivity extends AppCompatActivity { @Override public void afterTextChanged(Editable s) { - String[] text = (s+"").split("/"); - System.out.println(Arrays.toString(text)); + String[] text = (s + "").split("/"); - if(text.length>2){ + if (text.length > 2) { int group = adapter.getGroupPos(text[1]); - int child = adapter.getChildPos(text[1],text[2]); - ExpandableListView listView = findViewById(R.id.listView); - System.out.println(child); - clean(listView); + if (group != -1) { + int child = adapter.getChildPos(text[1], text[2]); + ExpandableListView listView = findViewById(R.id.listView); + listView.expandGroup(group); + if (adapter.childContains(text[1], text[2])) { + field.setBackgroundColor(Color.TRANSPARENT); + } else { + field.setBackgroundColor(Color.RED); + } - listView.expandGroup(group); - if(child!=-1){ - int pos = listView.getFlatListPosition(listView.getPackedPositionForChild(group,child)); - if(listView.getChildAt(pos) != null) - (listView.getChildAt(pos)).setBackgroundColor(Color.LTGRAY); - field.setBackgroundColor(Color.TRANSPARENT); + if (child != -1) { + adapter.select(group, child); + adapter.notifyDataSetChanged(); + } } else { field.setBackgroundColor(Color.RED); } - } else if(text.length==2){ + } else if (text.length > 1) { int group = adapter.getGroupPos(text[1]); - clean(listView); - - - if(group != -1){ - - - int counter = 0; - for (int i = 0; i < group; i++) { - counter += adapter.getChildrenCount(i); - counter++; - } - - if(listView.getChildAt(counter) != null) - (listView.getChildAt(counter)).setBackgroundColor(Color.LTGRAY); + if (adapter.groupContains(text[1])) { field.setBackgroundColor(Color.TRANSPARENT); } else { -// for (int i = 0; i < adapter.getGroupCount(); i++) { -// listView.collapseGroup(i); -// } field.setBackgroundColor(Color.RED); } + } else if (text.length > 0) { + if (!text[0].equals("/")) + field.setBackgroundColor(Color.RED); } else { - field.setBackgroundColor(Color.RED); + field.setBackgroundColor(Color.TRANSPARENT); } - } }); -} - - - - - public void clean(ExpandableListView v){ - int counter = 0; - for (int i = 0; i < adapter.getGroupCount(); i++) { - counter += adapter.getChildrenCount(i); - } - counter+= adapter.getGroupCount(); - for (int i = 0; i < counter; i++) { - if(v.getChildAt(i) != null) - (v.getChildAt(i)).setBackgroundColor(Color.TRANSPARENT); - } } - public void select(String name){ + public void select(String name) { selection = name; TextView text = findViewById(R.id.text); text.setText(name); } - public HashMap<String,List<String>> getData(){ + public HashMap<String, List<String>> getData() { HashMap<String, List<String>> data = new HashMap<String, List<String>>(); List<String> light = new ArrayList<>(); diff --git a/f2/app/src/main/java/com/example/f2/TestAdapter.java b/lab2/app/src/main/java/com/example/f2/TestAdapter.java similarity index 68% rename from f2/app/src/main/java/com/example/f2/TestAdapter.java rename to lab2/app/src/main/java/com/example/f2/TestAdapter.java index a8cca94dc2aad56de22b84d068407fae27edaa0c..27467b04881fe51f509a2146e58d24a021c7b8e1 100644 --- a/f2/app/src/main/java/com/example/f2/TestAdapter.java +++ b/lab2/app/src/main/java/com/example/f2/TestAdapter.java @@ -20,16 +20,15 @@ public class TestAdapter extends BaseExpandableListAdapter { private int selectedGroup = 0; private int selectedChild = 0; - public TestAdapter(Context c, List<String> titles, HashMap<String, List<String>> data){ + public TestAdapter(Context c, List<String> titles, HashMap<String, List<String>> data) { context = c; listTitles = titles; listDetail = data; } - public void select(int group, int child){ + public void select(int group, int child) { selectedChild = child; selectedGroup = group; -// getChildView(group,child,false,null,) } @Override @@ -52,11 +51,38 @@ public class TestAdapter extends BaseExpandableListAdapter { return listDetail.get(getGroup(groupPosition)).get(childPosition); } - public int getChildPos(String group, String child){ + public int getChildPos(String group, String child) { return (listDetail.get(group)).indexOf(child); } - public int getGroupPos(String group){ + public List<String> getChildList(String group) { + return listDetail.get(group); + } + + + public boolean groupContains(String group) { + for (String title : listTitles) { + if(title.length()<group.length()) continue; + String tmp = title.substring(0, group.length()); + if (tmp.equals(group)) return true; + } + return false; + } + + public boolean childContains(String group, String child) { + if (getGroupPos(group) == -1){ + return false; + } + for (String child1 : getChildList(group)) { + if(child1.length()<child.length()) continue; + String tmp = child1.substring(0, child.length()); + if (tmp.equals(child)) + return true; + } + return false; + } + + public int getGroupPos(String group) { return listTitles.indexOf(group); } @@ -78,7 +104,7 @@ public class TestAdapter extends BaseExpandableListAdapter { @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { String name = (String) getGroup(groupPosition); - if(convertView == null){ + if (convertView == null) { LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = layoutInflater.inflate(R.layout.list_group, null); } @@ -91,20 +117,17 @@ public class TestAdapter extends BaseExpandableListAdapter { @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { String name = (String) getChild(groupPosition, childPosition); - if(convertView == null){ + if (convertView == null) { LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = layoutInflater.inflate(R.layout.list_item, null); } TextView titleView = (TextView) convertView.findViewById(R.id.textItem); titleView.setText(name); -// System.out.println(((ExpandableListView) parent).getSelectedPosition()); -// if(selectedChild == childPosition && selectedGroup == groupPosition){ -//// titleView.setTypeface(null, Typeface.BOLD); -// titleView.setBackgroundColor(Color.RED); -// } else { -//// titleView.setTypeface(null, Typeface.NORMAL); -// titleView.setBackgroundColor(Color.TRANSPARENT); -// } + if (selectedChild == childPosition && selectedGroup == groupPosition) { + convertView.setBackgroundColor(Color.LTGRAY); + } else { + convertView.setBackgroundColor(Color.TRANSPARENT); + } return convertView; } diff --git a/f2/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/lab2/app/src/main/res/drawable-v24/ic_launcher_foreground.xml similarity index 100% rename from f2/app/src/main/res/drawable-v24/ic_launcher_foreground.xml rename to lab2/app/src/main/res/drawable-v24/ic_launcher_foreground.xml diff --git a/f2/app/src/main/res/drawable/ic_launcher_background.xml b/lab2/app/src/main/res/drawable/ic_launcher_background.xml similarity index 100% rename from f2/app/src/main/res/drawable/ic_launcher_background.xml rename to lab2/app/src/main/res/drawable/ic_launcher_background.xml diff --git a/f2/app/src/main/res/drawable/list_selector.xml b/lab2/app/src/main/res/drawable/list_selector.xml similarity index 100% rename from f2/app/src/main/res/drawable/list_selector.xml rename to lab2/app/src/main/res/drawable/list_selector.xml diff --git a/f2/app/src/main/res/layout/activity_main.xml b/lab2/app/src/main/res/layout/activity_main.xml similarity index 84% rename from f2/app/src/main/res/layout/activity_main.xml rename to lab2/app/src/main/res/layout/activity_main.xml index 7df1407f241e643f32840acfa3e0739078a7a125..20b383e474b6bd630f709598539612792673cda2 100644 --- a/f2/app/src/main/res/layout/activity_main.xml +++ b/lab2/app/src/main/res/layout/activity_main.xml @@ -10,7 +10,7 @@ android:id="@+id/listView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="100dp" + android:layout_marginTop="10dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" @@ -20,10 +20,10 @@ <EditText android:id="@+id/text" - android:layout_width="wrap_content" - android:layout_height="wrap_content" + android:layout_width="413dp" + android:layout_height="62dp" android:text="/" - app:layout_constraintEnd_toEndOf="parent" + android:textSize="24sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/f2/app/src/main/res/layout/list_group.xml b/lab2/app/src/main/res/layout/list_group.xml similarity index 100% rename from f2/app/src/main/res/layout/list_group.xml rename to lab2/app/src/main/res/layout/list_group.xml diff --git a/f2/app/src/main/res/layout/list_item.xml b/lab2/app/src/main/res/layout/list_item.xml similarity index 100% rename from f2/app/src/main/res/layout/list_item.xml rename to lab2/app/src/main/res/layout/list_item.xml diff --git a/f2/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/lab2/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from f2/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml rename to lab2/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/f2/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/lab2/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from f2/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml rename to lab2/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/f2/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/lab2/app/src/main/res/mipmap-hdpi/ic_launcher.webp similarity index 100% rename from f2/app/src/main/res/mipmap-hdpi/ic_launcher.webp rename to lab2/app/src/main/res/mipmap-hdpi/ic_launcher.webp diff --git a/f2/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/lab2/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp similarity index 100% rename from f2/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp rename to lab2/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp diff --git a/f2/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/lab2/app/src/main/res/mipmap-mdpi/ic_launcher.webp similarity index 100% rename from f2/app/src/main/res/mipmap-mdpi/ic_launcher.webp rename to lab2/app/src/main/res/mipmap-mdpi/ic_launcher.webp diff --git a/f2/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/lab2/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp similarity index 100% rename from f2/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp rename to lab2/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp diff --git a/f2/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/lab2/app/src/main/res/mipmap-xhdpi/ic_launcher.webp similarity index 100% rename from f2/app/src/main/res/mipmap-xhdpi/ic_launcher.webp rename to lab2/app/src/main/res/mipmap-xhdpi/ic_launcher.webp diff --git a/f2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/lab2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp similarity index 100% rename from f2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp rename to lab2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp diff --git a/f2/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/lab2/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp similarity index 100% rename from f2/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp rename to lab2/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp diff --git a/f2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/lab2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp similarity index 100% rename from f2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp rename to lab2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp diff --git a/f2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/lab2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp similarity index 100% rename from f2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp rename to lab2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp diff --git a/f2/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/lab2/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp similarity index 100% rename from f2/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp rename to lab2/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp diff --git a/f2/app/src/main/res/values-night/themes.xml b/lab2/app/src/main/res/values-night/themes.xml similarity index 100% rename from f2/app/src/main/res/values-night/themes.xml rename to lab2/app/src/main/res/values-night/themes.xml diff --git a/f2/app/src/main/res/values/colors.xml b/lab2/app/src/main/res/values/colors.xml similarity index 100% rename from f2/app/src/main/res/values/colors.xml rename to lab2/app/src/main/res/values/colors.xml diff --git a/f2/app/src/main/res/values/strings.xml b/lab2/app/src/main/res/values/strings.xml similarity index 100% rename from f2/app/src/main/res/values/strings.xml rename to lab2/app/src/main/res/values/strings.xml diff --git a/f2/app/src/main/res/values/themes.xml b/lab2/app/src/main/res/values/themes.xml similarity index 100% rename from f2/app/src/main/res/values/themes.xml rename to lab2/app/src/main/res/values/themes.xml diff --git a/f2/app/src/test/java/com/example/f2/ExampleUnitTest.java b/lab2/app/src/test/java/com/example/f2/ExampleUnitTest.java similarity index 100% rename from f2/app/src/test/java/com/example/f2/ExampleUnitTest.java rename to lab2/app/src/test/java/com/example/f2/ExampleUnitTest.java diff --git a/f2/build.gradle b/lab2/build.gradle similarity index 100% rename from f2/build.gradle rename to lab2/build.gradle diff --git a/f2/gradle.properties b/lab2/gradle.properties similarity index 100% rename from f2/gradle.properties rename to lab2/gradle.properties diff --git a/f2/gradle/wrapper/gradle-wrapper.jar b/lab2/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from f2/gradle/wrapper/gradle-wrapper.jar rename to lab2/gradle/wrapper/gradle-wrapper.jar diff --git a/f2/gradle/wrapper/gradle-wrapper.properties b/lab2/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from f2/gradle/wrapper/gradle-wrapper.properties rename to lab2/gradle/wrapper/gradle-wrapper.properties diff --git a/f2/gradlew b/lab2/gradlew similarity index 100% rename from f2/gradlew rename to lab2/gradlew diff --git a/f2/gradlew.bat b/lab2/gradlew.bat similarity index 100% rename from f2/gradlew.bat rename to lab2/gradlew.bat diff --git a/f2/settings.gradle b/lab2/settings.gradle similarity index 100% rename from f2/settings.gradle rename to lab2/settings.gradle