Skip to content

Commit 70ef503

Browse files
committed
first commit
0 parents  commit 70ef503

File tree

25 files changed

+1048
-0
lines changed

25 files changed

+1048
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

EasyWidgets/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

EasyWidgets/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'com.android.library'
3+
}
4+
5+
android {
6+
compileSdkVersion 30
7+
buildToolsVersion "30.0.3"
8+
9+
defaultConfig {
10+
minSdkVersion 23
11+
targetSdkVersion 30
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
consumerProguardFiles "consumer-rules.pro"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.3.0'
34+
implementation 'com.google.android.material:material:1.3.0'
35+
testImplementation 'junit:junit:4.+'
36+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
37+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
38+
}

EasyWidgets/consumer-rules.pro

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.easywidgets.lists;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.listview.easylist.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.easywidgets.lists">
4+
5+
</manifest>
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.easywidgets.lists;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.ArrayAdapter;
8+
import android.widget.ImageView;
9+
import android.widget.TextView;
10+
11+
import androidx.annotation.NonNull;
12+
import androidx.annotation.Nullable;
13+
14+
import java.util.ArrayList;
15+
16+
/**
17+
* An extended version {@link ArrayAdapter} used for making custom listviews. You can make 2 types of listview using this adapter.
18+
* @see R.layout#list
19+
*/
20+
public class ListAdapter extends ArrayAdapter<String> {
21+
22+
private final Context context;
23+
private String[] titles;
24+
private String[] headings;
25+
private String[] summaries;
26+
private ArrayList<ListAdapterObject> objects;
27+
private int[] images;
28+
private final int LIST;
29+
30+
/**
31+
* Creates an adapter with 2 textview, one for heading & another for summery.
32+
* @param context The context of activity
33+
* @param line1 The text to set as heading
34+
* @param line2 The text to set as summery
35+
*/
36+
public ListAdapter(@NonNull Context context, String[] line1, String[] line2) {
37+
super(context, android.R.layout.simple_list_item_2);
38+
this.titles = line1;
39+
this.headings = line2;
40+
this.context = context;
41+
LIST = 0;
42+
}
43+
44+
/**
45+
* Creates an adapter with 3 textview & a imageview, 1st two for title & heading and another one for some meta data. You can pass
46+
* <code>null</code> if you don't want 3rd textview.
47+
* @param context The context of activity
48+
* @param images The image resource id to set as drawableStart or icon.
49+
* @param titles The text array to set as titles
50+
* @param headings The text array to set as headings
51+
* @param meta The text array to set as meta information
52+
*/
53+
public ListAdapter(@NonNull Context context, int[] images, String[] titles, String[] headings, @Nullable String[] meta){
54+
super(context,R.layout.list);
55+
this.titles = titles;
56+
this.headings = headings;
57+
this.summaries = meta;
58+
this.images = images;
59+
this.context = context;
60+
LIST = 1;
61+
}
62+
63+
/**
64+
* Creates an adapter with 3 textview & a imageview, 1st two for title & heading and another one for some meta data. You can pass
65+
* <code>null</code> if you don't want 3rd textview.
66+
*
67+
* @param objects A {@link ListAdapterObject} POJO to set parameters of the listview
68+
*/
69+
public ListAdapter(@NonNull Context context, ArrayList<ListAdapterObject> objects){
70+
super(context,R.layout.list);
71+
this.objects = objects;
72+
this.context = context;
73+
LIST = 1;
74+
}
75+
76+
@NonNull
77+
@Override
78+
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
79+
View view;
80+
if (LIST == 0){
81+
view = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2,parent,false);
82+
TextView title = view.findViewById(android.R.id.text1);
83+
TextView heading = view.findViewById(android.R.id.text2);
84+
85+
title.setText(titles[position]);
86+
heading.setText(headings[position]);
87+
} else {
88+
view = LayoutInflater.from(context).inflate(R.layout.list,parent,false);
89+
TextView title = view.findViewById(R.id.title);
90+
TextView heading = view.findViewById(R.id.heading);
91+
TextView summary = view.findViewById(R.id.summery);
92+
ImageView icon = view.findViewById(R.id.icon);
93+
94+
if (objects == null){
95+
title.setText(titles[position]);
96+
heading.setText(headings[position]);
97+
summary.setText(summaries != null ? summaries[position] : "");
98+
icon.setImageResource(images[position]);
99+
} else {
100+
ListAdapterObject object = objects.get(position);
101+
title.setText(object.getTitle());
102+
heading.setText(object.getHeading());
103+
summary.setText(object.getSummary() != null ? object.getSummary() : "");
104+
icon.setImageResource(object.getIcon());
105+
}
106+
}
107+
return view;
108+
}
109+
110+
@Override
111+
public int getCount() {
112+
return objects != null ? objects.size() : titles.length;
113+
}
114+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.easywidgets.lists;
2+
3+
import androidx.annotation.Nullable;
4+
5+
public class ListAdapterObject {
6+
7+
private String title;
8+
private String heading;
9+
private String summary;
10+
private int icon;
11+
12+
public ListAdapterObject(int icon, String title, String heading, @Nullable String summary){
13+
this.title = title;
14+
this.heading = heading;
15+
this.summary = summary;
16+
this.icon = icon;
17+
}
18+
19+
public ListAdapterObject(){} // Requires an empty constructor, in case if you are using firebase database.
20+
21+
public String getTitle() {
22+
return title;
23+
}
24+
25+
public void setTitle(String title) {
26+
this.title = title;
27+
}
28+
29+
public String getHeading() {
30+
return heading;
31+
}
32+
33+
public void setHeading(String heading) {
34+
this.heading = heading;
35+
}
36+
37+
public @Nullable String getSummary() {
38+
return summary;
39+
}
40+
41+
public void setSummary(String summary) {
42+
this.summary = summary;
43+
}
44+
45+
public int getIcon() {
46+
return icon;
47+
}
48+
49+
public void setIcon(int icon) {
50+
this.icon = icon;
51+
}
52+
}

0 commit comments

Comments
 (0)