mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-19 20:02:16 +02:00
improved inflation of modules (layout file)
This commit is contained in:
parent
3ffb1a1825
commit
5f99fc9bb9
@ -4,7 +4,6 @@ import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
@ -63,22 +62,21 @@ public class ModulesActivity extends Activity {
|
||||
}
|
||||
|
||||
// configure info
|
||||
((TextView) views.findViewById(R.id.label)).setText(module.getName());
|
||||
final TextView title = views.findViewById(R.id.label);
|
||||
title.setText(module.getName());
|
||||
((TextView) views.findViewById(R.id.desc)).setText(module.getDescription());
|
||||
|
||||
// configure toggleable description
|
||||
final View details_cont = views.findViewById(R.id.details);
|
||||
View toggle = views.findViewById(R.id.toggle);
|
||||
toggle.setOnClickListener(new View.OnClickListener() {
|
||||
title.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean checked = v.getTag() != null;
|
||||
v.setTag(checked ? null : new Object());
|
||||
boolean checked = details_cont.getVisibility() == View.GONE;
|
||||
details_cont.setVisibility(checked ? View.VISIBLE : View.GONE);
|
||||
((ImageView) v).setImageResource(checked ? R.drawable.expanded : R.drawable.collapsed);
|
||||
title.setCompoundDrawablesWithIntrinsicBounds(checked ? R.drawable.expanded : R.drawable.collapsed, 0, 0, 0);
|
||||
}
|
||||
});
|
||||
toggle.performClick();
|
||||
title.performClick();
|
||||
|
||||
// add configurations
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@ -14,6 +15,7 @@ import com.trianguloy.urlchecker.R;
|
||||
import com.trianguloy.urlchecker.modules.AModuleData;
|
||||
import com.trianguloy.urlchecker.modules.AModuleDialog;
|
||||
import com.trianguloy.urlchecker.modules.ModuleManager;
|
||||
import com.trianguloy.urlchecker.utilities.Inflater;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -100,26 +102,16 @@ public class MainDialog extends Activity {
|
||||
modules.clear();
|
||||
|
||||
// top module
|
||||
initializeModule(ModuleManager.topModule);
|
||||
initializeModule(ModuleManager.topModule, false);
|
||||
|
||||
// middle modules
|
||||
final List<AModuleData> middleModules = ModuleManager.getEnabledMiddleModules(this);
|
||||
for (AModuleData module : middleModules) {
|
||||
|
||||
// set title
|
||||
String name = module.getName();
|
||||
if (name != null) {
|
||||
final TextView title = new TextView(this);
|
||||
title.setText(name + ":");
|
||||
ll_mods.addView(title);
|
||||
}
|
||||
|
||||
// set content
|
||||
initializeModule(module);
|
||||
initializeModule(module, true);
|
||||
}
|
||||
|
||||
// bottom module
|
||||
initializeModule(ModuleManager.bottomModule);
|
||||
initializeModule(ModuleManager.bottomModule, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,13 +119,26 @@ public class MainDialog extends Activity {
|
||||
*
|
||||
* @param moduleData which module to initialize
|
||||
*/
|
||||
private void initializeModule(AModuleData moduleData) {
|
||||
private void initializeModule(AModuleData moduleData, boolean decorations) {
|
||||
try {
|
||||
// enabled, add
|
||||
AModuleDialog module = moduleData.getDialog(this);
|
||||
View views = getLayoutInflater().inflate(module.getLayoutDialog(), ll_mods, false);
|
||||
ll_mods.addView(views); // separated to return the inflated view instead of the parent
|
||||
module.onInitialize(views);
|
||||
|
||||
ViewGroup parent;
|
||||
// set module block
|
||||
if (decorations) {
|
||||
View block = Inflater.inflate(R.layout.dialog_module, ll_mods, this);
|
||||
final TextView title = block.findViewById(R.id.title);
|
||||
title.setText(moduleData.getName() + ":");
|
||||
parent = block.findViewById(R.id.mod);
|
||||
} else {
|
||||
parent = ll_mods;
|
||||
}
|
||||
|
||||
// set module content
|
||||
View child = Inflater.inflate(module.getLayoutDialog(), parent, this);
|
||||
module.onInitialize(child);
|
||||
|
||||
modules.add(module);
|
||||
} catch (Exception e) {
|
||||
// can't add module
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.trianguloy.urlchecker.utilities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class Inflater {
|
||||
static public <T extends View> T inflate(int resource, ViewGroup root, Activity cntx) {
|
||||
final View view = cntx.getLayoutInflater().inflate(resource, root, false);
|
||||
root.addView(view);
|
||||
return ((T) view);
|
||||
}
|
||||
}
|
@ -4,13 +4,14 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp"
|
||||
tools:context=".activities.ModulesActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="List of modules: You can enable or disable them, also check its description and configuration" />
|
||||
android:text="List of modules: You can enable or disable them, also check its description and configuration." />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/list"
|
||||
|
@ -1,28 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
android:padding="5dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/collapsed" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical" />
|
||||
android:drawableStart="@drawable/collapsed"
|
||||
android:drawableLeft="@drawable/collapsed"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="5dp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
@ -42,14 +38,14 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="25dp">
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/desc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="TextView" />
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
21
app/src/main/res/layout/dialog_module.xml
Normal file
21
app/src/main/res/layout/dialog_module.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/mod"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp">
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user