Improve license activity design

Julien LepillerSun Jul 10 15:36:39+0200 2022

bf9c907

Improve license activity design

.idea/misc.xml

1414
        <entry key="app/src/main/res/layout/content_main.xml" value="0.2078125" />
1515
        <entry key="app/src/main/res/layout/content_radicals.xml" value="0.1" />
1616
        <entry key="app/src/main/res/layout/fragment_results.xml" value="0.2078125" />
17+
        <entry key="app/src/main/res/layout/layout_dictionary.xml" value="0.3932291666666667" />
1718
        <entry key="app/src/main/res/layout/layout_example.xml" value="0.20677083333333332" />
1819
        <entry key="app/src/main/res/layout/layout_license.xml" value="0.20677083333333332" />
1920
        <entry key="app/src/main/res/layout/layout_license_description.xml" value="0.21927083333333333" />

app/src/main/java/eu/lepiller/nani/LicenseActivity.java

11
package eu.lepiller.nani;
22
3+
import android.graphics.drawable.Drawable;
34
import android.os.Bundle;
45
import android.widget.ExpandableListAdapter;
56
import android.widget.ExpandableListView;

78
89
import androidx.annotation.Nullable;
910
import androidx.appcompat.app.AppCompatActivity;
11+
import androidx.core.content.res.ResourcesCompat;
1012
1113
import java.util.ArrayList;
1214
import java.util.List;

1719
    public static class License {
1820
        private final String name, description, license;
1921
        private final List<License> subProjects;
20-
        License(String name, String description, String license, List<License> subProjects) {
22+
        private final Drawable drawable;
23+
24+
        License(String name, Drawable drawable, String description, String license, List<License> subProjects) {
2125
            this.name = name;
26+
            this.drawable = drawable;
2227
            this.description = description;
2328
            this.license = license;
2429
            this.subProjects = subProjects;

4045
        public List<License> getSubProjects() {
4146
            return subProjects;
4247
        }
48+
49+
        public Drawable getDrawable() {
50+
            return drawable;
51+
        }
4352
    }
4453
4554
    private static final List<License> licenseInformation = new ArrayList<>();

5160
5261
        licenseInformation.clear();
5362
        List<License> erdrgLicenses = new ArrayList<>();
54-
        erdrgLicenses.add(new License(getString(R.string.jmdict_title), getString(R.string.jmdict_descr), getString(R.string.jmdict_license), null));
55-
        erdrgLicenses.add(new License(getString(R.string.radk_title), getString(R.string.radk_descr), getString(R.string.radk_license), null));
56-
        erdrgLicenses.add(new License(getString(R.string.kanjidic_title), getString(R.string.kanjidic_descr), getString(R.string.kanjidic_license), null));
63+
        erdrgLicenses.add(new License(getString(R.string.jmdict_title), null,
64+
                getString(R.string.jmdict_descr), getString(R.string.jmdict_license), null));
65+
        erdrgLicenses.add(new License(getString(R.string.radk_title), null,
66+
                getString(R.string.radk_descr), getString(R.string.radk_license), null));
67+
        erdrgLicenses.add(new License(getString(R.string.kanjidic_title), null,
68+
                getString(R.string.kanjidic_descr), getString(R.string.kanjidic_license), null));
5769
        licenseInformation.add(
58-
                new License(getString(R.string.erdrg_title), getString(R.string.erdrg_descr), "",
59-
                        erdrgLicenses));
70+
                new License(getString(R.string.erdrg_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_nani_edrdg, getTheme()),
71+
                        getString(R.string.erdrg_descr), "", erdrgLicenses));
6072
6173
        licenseInformation.add(
62-
                new License(getString(R.string.kanjivg_title), getString(R.string.kanjivg_descr), getString(R.string.kanjivg_license), null)
74+
                new License(getString(R.string.kanjivg_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_kanjivg, getTheme()),
75+
                        getString(R.string.kanjivg_descr), getString(R.string.kanjivg_license), null)
6376
        );
6477
        licenseInformation.add(
65-
                new License(getString(R.string.jibiki_title), getString(R.string.jibiki_descr), getString(R.string.jibiki_license), null)
78+
                new License(getString(R.string.jibiki_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_jibiki, getTheme()),
79+
                        getString(R.string.jibiki_descr), getString(R.string.jibiki_license), null)
6680
        );
6781
        licenseInformation.add(
68-
                new License(getString(R.string.wadoku_title), getString(R.string.wadoku_descr), getString(R.string.wadoku_license), null)
82+
                new License(getString(R.string.wadoku_title), ResourcesCompat.getDrawable(getResources(), R.drawable.wadoku, getTheme()),
83+
                        getString(R.string.wadoku_descr), getString(R.string.wadoku_license), null)
6984
        );
7085
        licenseInformation.add(
71-
                new License(getString(R.string.tatoeba_title), getString(R.string.tatoeba_descr), getString(R.string.tatoeba_license), null)
86+
                new License(getString(R.string.tatoeba_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_tatoeba, getTheme()),
87+
                        getString(R.string.tatoeba_descr), getString(R.string.tatoeba_license), null)
7288
        );
7389
7490
        final ExpandableListView list_view = findViewById(R.id.license_view);

app/src/main/java/eu/lepiller/nani/LicenseAdapter.java

11
package eu.lepiller.nani;
22
33
import android.content.Context;
4+
import android.graphics.drawable.Drawable;
5+
import android.provider.ContactsContract;
46
import android.view.LayoutInflater;
57
import android.view.View;
68
import android.view.ViewGroup;
79
import android.widget.BaseExpandableListAdapter;
10+
import android.widget.ImageView;
811
import android.widget.TextView;
912
1013
import java.util.List;

6467
            view = layoutInflater.inflate(R.layout.layout_license_name, viewGroup, false);
6568
        }
6669
        String name = licenses.get(i).getName();
70+
        Drawable icon = licenses.get(i).getDrawable();
6771
        TextView nameView = (TextView) view.findViewById(R.id.license_name);
72+
        ImageView iconView = (ImageView) view.findViewById(R.id.icon_view);
73+
        ImageView arrowView = (ImageView) view.findViewById(R.id.arrow_view);
6874
        nameView.setText(name);
75+
        iconView.setImageDrawable(icon);
76+
        arrowView.setImageResource(b? android.R.drawable.arrow_up_float: android.R.drawable.arrow_down_float);
6977
        return view;
7078
    }
7179

app/src/main/res/layout/activity_license.xml

1414
        android:textColor="@color/colorTitle"
1515
        android:textSize="@dimen/title_size" />
1616
17+
    <TextView
18+
        android:layout_width="wrap_content"
19+
        android:layout_height="wrap_content"
20+
        android:layout_gravity="center"
21+
        android:text="@string/data_intro" />
22+
1723
    <ExpandableListView
1824
        android:id="@+id/license_view"
1925
        android:layout_width="match_parent"

app/src/main/res/layout/layout_license_name.xml

22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
    android:layout_width="match_parent"
44
    android:layout_height="match_parent"
5-
    android:orientation="vertical">
5+
    xmlns:app="http://schemas.android.com/apk/res-auto"
6+
    android:orientation="horizontal">
7+
8+
    <ImageView
9+
        android:id="@+id/icon_view"
10+
        android:layout_width="64dp"
11+
        android:layout_height="64dp"
12+
        android:layout_gravity="center"
13+
        android:layout_margin="16dp"
14+
        android:contentDescription="@string/alt_text_icon"
15+
        android:layout_weight="0"
16+
        app:srcCompat="@android:drawable/ic_menu_close_clear_cancel" />
17+
618
    <TextView
719
        android:id="@+id/license_name"
820
        android:layout_width="match_parent"
921
        android:layout_height="wrap_content"
22+
        android:layout_weight="1"
1023
        android:layout_marginTop="16dp"
1124
        android:textColor="@color/colorSubtitle"
1225
        android:textSize="@dimen/title_size"/>
26+
27+
    <ImageView
28+
        android:id="@+id/arrow_view"
29+
        android:layout_width="16dp"
30+
        android:layout_height="16dp"
31+
        android:layout_gravity="center"
32+
        android:layout_margin="16dp"
33+
        android:contentDescription="@string/alt_text_icon"
34+
        android:layout_weight="0"
35+
        app:srcCompat="@android:drawable/arrow_down_float" />
1336
</LinearLayout>
1336=
1437=
\ No newline at end of file