├── .gitignore
├── LICENSE
├── README.md
├── app
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-playstore.png
│ ├── java
│ └── www
│ │ └── technovimal
│ │ └── in
│ │ └── nativerecyclerview
│ │ ├── Contact.java
│ │ ├── ContactsAdapter.java
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ └── ic_launcher_foreground.xml
│ ├── layout
│ ├── activity_main.xml
│ └── item_contact.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── ic_launcher_background.xml
│ ├── strings.xml
│ └── styles.xml
├── art
├── demo1.png
└── demo2.png
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── gradlew.bat
├── local.properties
├── nativetemplates
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── google
│ │ ├── nativetemplates
│ │ ├── NativeTemplateStyle.java
│ │ └── TemplateView.java
│ │ └── rvadapter
│ │ ├── AdmobNativeAdAdapter.java
│ │ └── RecyclerViewAdapterWrapper.java
│ └── res
│ ├── drawable
│ ├── ad_mark.png
│ ├── bg_ad_btn_common.xml
│ └── gnt_outline_shape.xml
│ ├── layout
│ ├── gnt_custom_small_template_view.xml
│ ├── gnt_medium_template_view.xml
│ ├── gnt_small_template_view.xml
│ ├── item_admob_native_ad.xml
│ └── item_admob_native_ad_outline.xml
│ ├── values-night
│ └── colors.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RecyclerView-Native-ads-Example
2 | Place Admob Native Advanced Ads in recycler view android studiooooo!
3 |
4 | 
5 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 30
5 |
6 | defaultConfig {
7 | applicationId "com.efaso.admobadvancednativerecyclerview"
8 | minSdkVersion 16
9 | targetSdkVersion 30
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 |
15 | compileOptions {
16 | sourceCompatibility JavaVersion.VERSION_1_8
17 | targetCompatibility JavaVersion.VERSION_1_8
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation 'androidx.appcompat:appcompat:1.2.0'
31 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
32 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
33 | implementation project(path: ':nativetemplates')
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/java/www/technovimal/in/nativerecyclerview/Contact.java:
--------------------------------------------------------------------------------
1 | package www.technovimal.in.nativerecyclerview;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Contact {
6 | private final String mName;
7 | private final boolean mOnline;
8 |
9 | public Contact(String name, boolean online) {
10 | mName = name;
11 | mOnline = online;
12 | }
13 |
14 | public String getName() {
15 | return mName;
16 | }
17 |
18 | public boolean isOnline() {
19 | return mOnline;
20 | }
21 |
22 | private static int lastContactId = 0;
23 |
24 | public static ArrayList createContactsList(int numContacts) {
25 | ArrayList contacts = new ArrayList();
26 |
27 | for (int i = 1; i <= numContacts; i++) {
28 | contacts.add(new Contact("Person " + ++lastContactId, i <= numContacts / 2));
29 | }
30 |
31 | return contacts;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/www/technovimal/in/nativerecyclerview/ContactsAdapter.java:
--------------------------------------------------------------------------------
1 | package www.technovimal.in.nativerecyclerview;
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.Button;
8 | import android.widget.TextView;
9 |
10 | import androidx.recyclerview.widget.RecyclerView;
11 |
12 | import java.util.List;
13 |
14 | public class ContactsAdapter extends RecyclerView.Adapter {
15 |
16 | private final List mContacts;
17 | public ContactsAdapter(List contacts) {
18 | mContacts = contacts;
19 | }
20 |
21 | @Override
22 | public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
23 | Context context = parent.getContext();
24 | LayoutInflater inflater = LayoutInflater.from(context);
25 | View contactView = inflater.inflate(R.layout.item_contact, parent, false);
26 | ViewHolder viewHolder = new ViewHolder(contactView);
27 | return viewHolder;
28 | }
29 | @Override
30 | public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) {
31 | Contact contact = mContacts.get(position);
32 | TextView textView = viewHolder.nameTextView;
33 | textView.setText(contact.getName());
34 | Button button = viewHolder.messageButton;
35 | button.setText(contact.isOnline() ? "Message" : "Offline");
36 | button.setEnabled(contact.isOnline());
37 | }
38 |
39 | @Override
40 | public int getItemCount() {
41 | return mContacts.size();
42 | }
43 |
44 | public static class ViewHolder extends RecyclerView.ViewHolder {
45 | public TextView nameTextView;
46 | public Button messageButton;
47 | public ViewHolder(View itemView) {
48 | super(itemView);
49 | nameTextView = itemView.findViewById(R.id.contact_name);
50 | messageButton = itemView.findViewById(R.id.message_button);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/www/technovimal/in/nativerecyclerview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package www.technovimal.in.nativerecyclerview;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import androidx.recyclerview.widget.LinearLayoutManager;
7 | import androidx.recyclerview.widget.RecyclerView;
8 |
9 | import com.google.rvadapter.AdmobNativeAdAdapter;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | ArrayList contacts;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 |
24 | List list = new ArrayList<>();
25 | for(int i=0;i<30;i++){
26 | list.add("Let's save the world "+i);
27 | }
28 |
29 |
30 | RecyclerView rvContacts = findViewById(R.id.rvContacts);
31 | contacts = Contact.createContactsList(20);
32 | ContactsAdapter adapter = new ContactsAdapter(contacts);
33 |
34 |
35 |
36 |
37 |
38 | //////////
39 | AdmobNativeAdAdapter admobNativeAdAdapter = AdmobNativeAdAdapter.Builder.with("ca-app-pub-3940256099942544/2247696110", adapter,
40 | "small").adItemInterval(1).build();
41 | rvContacts.setAdapter(admobNativeAdAdapter);
42 | rvContacts.setLayoutManager(new LinearLayoutManager(this));
43 |
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_contact.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
18 |
19 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #167EDB
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Native RecyclerView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/art/demo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/art/demo1.png
--------------------------------------------------------------------------------
/art/demo2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/art/demo2.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:4.1.2'
11 |
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 |
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jan 25 11:20:26 ICT 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file must *NOT* be checked into Version Control Systems,
2 | # as it contains information specific to your local configuration.
3 | #
4 | # Location of the SDK. This is only used by Gradle.
5 | # For customization when using a Version Control System, please read the
6 | # header note.
7 | #Sat Feb 27 14:58:21 IST 2021
8 | sdk.dir=C\:\\Users\\vimal\\AppData\\Local\\Android\\Sdk
9 |
--------------------------------------------------------------------------------
/nativetemplates/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | group='com.github.daoibrahim'
6 | android {
7 | compileSdkVersion 29
8 | buildToolsVersion "29.0.2"
9 | //A library to allow using Admob Native Ads in android recyclerView
10 |
11 | defaultConfig {
12 | minSdkVersion 16
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | consumerProguardFiles 'consumer-rules.pro'
18 | }
19 |
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_8
22 | targetCompatibility JavaVersion.VERSION_1_8
23 | }
24 |
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
29 | }
30 | bf {
31 | }
32 | }
33 |
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 |
39 | implementation 'androidx.appcompat:appcompat:1.2.0'
40 |
41 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
42 |
43 | implementation 'com.google.android.gms:play-services-ads:19.7.0'
44 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
45 | }
46 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/java/com/google/nativetemplates/NativeTemplateStyle.java:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.google.nativetemplates;
16 |
17 | import android.graphics.Typeface;
18 | import android.graphics.drawable.ColorDrawable;
19 |
20 | /** A class containing the optional styling options for the Native Template. * */
21 | public class NativeTemplateStyle {
22 |
23 | // Call to action typeface.
24 | private Typeface callToActionTextTypeface;
25 |
26 | // Size of call to action text.
27 | private float callToActionTextSize;
28 |
29 | // Call to action typeface color in the form 0xAARRGGBB.
30 | private int callToActionTypefaceColor;
31 |
32 | // Call to action background color.
33 | private ColorDrawable callToActionBackgroundColor;
34 |
35 | // All templates have a primary text area which is populated by the native ad's headline.
36 |
37 | // Primary text typeface.
38 | private Typeface primaryTextTypeface;
39 |
40 | // Size of primary text.
41 | private float primaryTextSize;
42 |
43 | // Primary text typeface color in the form 0xAARRGGBB.
44 | private int primaryTextTypefaceColor;
45 |
46 | // Primary text background color.
47 | private ColorDrawable primaryTextBackgroundColor;
48 |
49 | // The typeface, typeface color, and background color for the second row of text in the template.
50 | // All templates have a secondary text area which is populated either by the body of the ad or
51 | // by the rating of the app.
52 |
53 | // Secondary text typeface.
54 | private Typeface secondaryTextTypeface;
55 |
56 | // Size of secondary text.
57 | private float secondaryTextSize;
58 |
59 | // Secondary text typeface color in the form 0xAARRGGBB.
60 | private int secondaryTextTypefaceColor;
61 |
62 | // Secondary text background color.
63 | private ColorDrawable secondaryTextBackgroundColor;
64 |
65 | // The typeface, typeface color, and background color for the third row of text in the template.
66 | // The third row is used to display store name or the default tertiary text.
67 |
68 | // Tertiary text typeface.
69 | private Typeface tertiaryTextTypeface;
70 |
71 | // Size of tertiary text.
72 | private float tertiaryTextSize;
73 |
74 | // Tertiary text typeface color in the form 0xAARRGGBB.
75 | private int tertiaryTextTypefaceColor;
76 |
77 | // Tertiary text background color.
78 | private ColorDrawable tertiaryTextBackgroundColor;
79 |
80 | // The background color for the bulk of the ad.
81 | private ColorDrawable mainBackgroundColor;
82 |
83 | public Typeface getCallToActionTextTypeface() {
84 | return callToActionTextTypeface;
85 | }
86 |
87 | public float getCallToActionTextSize() {
88 | return callToActionTextSize;
89 | }
90 |
91 | public int getCallToActionTypefaceColor() {
92 | return callToActionTypefaceColor;
93 | }
94 |
95 | public ColorDrawable getCallToActionBackgroundColor() {
96 | return callToActionBackgroundColor;
97 | }
98 |
99 | public Typeface getPrimaryTextTypeface() {
100 | return primaryTextTypeface;
101 | }
102 |
103 | public float getPrimaryTextSize() {
104 | return primaryTextSize;
105 | }
106 |
107 | public int getPrimaryTextTypefaceColor() {
108 | return primaryTextTypefaceColor;
109 | }
110 |
111 | public ColorDrawable getPrimaryTextBackgroundColor() {
112 | return primaryTextBackgroundColor;
113 | }
114 |
115 | public Typeface getSecondaryTextTypeface() {
116 | return secondaryTextTypeface;
117 | }
118 |
119 | public float getSecondaryTextSize() {
120 | return secondaryTextSize;
121 | }
122 |
123 | public int getSecondaryTextTypefaceColor() {
124 | return secondaryTextTypefaceColor;
125 | }
126 |
127 | public ColorDrawable getSecondaryTextBackgroundColor() {
128 | return secondaryTextBackgroundColor;
129 | }
130 |
131 | public Typeface getTertiaryTextTypeface() {
132 | return tertiaryTextTypeface;
133 | }
134 |
135 | public float getTertiaryTextSize() {
136 | return tertiaryTextSize;
137 | }
138 |
139 | public int getTertiaryTextTypefaceColor() {
140 | return tertiaryTextTypefaceColor;
141 | }
142 |
143 | public ColorDrawable getTertiaryTextBackgroundColor() {
144 | return tertiaryTextBackgroundColor;
145 | }
146 |
147 | public ColorDrawable getMainBackgroundColor() {
148 | return mainBackgroundColor;
149 | }
150 |
151 | /** A class that provides helper methods to build a style object. * */
152 | public static class Builder {
153 |
154 | private NativeTemplateStyle styles;
155 |
156 | public Builder() {
157 | this.styles = new NativeTemplateStyle();
158 | }
159 |
160 | public Builder withCallToActionTextTypeface(Typeface callToActionTextTypeface) {
161 | this.styles.callToActionTextTypeface = callToActionTextTypeface;
162 | return this;
163 | }
164 |
165 | public Builder withCallToActionTextSize(float callToActionTextSize) {
166 | this.styles.callToActionTextSize = callToActionTextSize;
167 | return this;
168 | }
169 |
170 | public Builder withCallToActionTypefaceColor(int callToActionTypefaceColor) {
171 | this.styles.callToActionTypefaceColor = callToActionTypefaceColor;
172 | return this;
173 | }
174 |
175 | public Builder withCallToActionBackgroundColor(ColorDrawable callToActionBackgroundColor) {
176 | this.styles.callToActionBackgroundColor = callToActionBackgroundColor;
177 | return this;
178 | }
179 |
180 | public Builder withPrimaryTextTypeface(Typeface primaryTextTypeface) {
181 | this.styles.primaryTextTypeface = primaryTextTypeface;
182 | return this;
183 | }
184 |
185 | public Builder withPrimaryTextSize(float primaryTextSize) {
186 | this.styles.primaryTextSize = primaryTextSize;
187 | return this;
188 | }
189 |
190 | public Builder withPrimaryTextTypefaceColor(int primaryTextTypefaceColor) {
191 | this.styles.primaryTextTypefaceColor = primaryTextTypefaceColor;
192 | return this;
193 | }
194 |
195 | public Builder withPrimaryTextBackgroundColor(ColorDrawable primaryTextBackgroundColor) {
196 | this.styles.primaryTextBackgroundColor = primaryTextBackgroundColor;
197 | return this;
198 | }
199 |
200 | public Builder withSecondaryTextTypeface(Typeface secondaryTextTypeface) {
201 | this.styles.secondaryTextTypeface = secondaryTextTypeface;
202 | return this;
203 | }
204 |
205 | public Builder withSecondaryTextSize(float secondaryTextSize) {
206 | this.styles.secondaryTextSize = secondaryTextSize;
207 | return this;
208 | }
209 |
210 | public Builder withSecondaryTextTypefaceColor(int secondaryTextTypefaceColor) {
211 | this.styles.secondaryTextTypefaceColor = secondaryTextTypefaceColor;
212 | return this;
213 | }
214 |
215 | public Builder withSecondaryTextBackgroundColor(ColorDrawable secondaryTextBackgroundColor) {
216 | this.styles.secondaryTextBackgroundColor = secondaryTextBackgroundColor;
217 | return this;
218 | }
219 |
220 | public Builder withTertiaryTextTypeface(Typeface tertiaryTextTypeface) {
221 | this.styles.tertiaryTextTypeface = tertiaryTextTypeface;
222 | return this;
223 | }
224 |
225 | public Builder withTertiaryTextSize(float tertiaryTextSize) {
226 | this.styles.tertiaryTextSize = tertiaryTextSize;
227 | return this;
228 | }
229 |
230 | public Builder withTertiaryTextTypefaceColor(int tertiaryTextTypefaceColor) {
231 | this.styles.tertiaryTextTypefaceColor = tertiaryTextTypefaceColor;
232 | return this;
233 | }
234 |
235 | public Builder withTertiaryTextBackgroundColor(ColorDrawable tertiaryTextBackgroundColor) {
236 | this.styles.tertiaryTextBackgroundColor = tertiaryTextBackgroundColor;
237 | return this;
238 | }
239 |
240 | public Builder withMainBackgroundColor(ColorDrawable mainBackgroundColor) {
241 | this.styles.mainBackgroundColor = mainBackgroundColor;
242 | return this;
243 | }
244 |
245 | public NativeTemplateStyle build() {
246 | return styles;
247 | }
248 | }
249 | }
250 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/java/com/google/nativetemplates/TemplateView.java:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.google.nativetemplates;
16 |
17 | import android.content.Context;
18 | import android.content.res.TypedArray;
19 | import android.graphics.Typeface;
20 | import android.graphics.drawable.Drawable;
21 | import android.os.Build;
22 | import android.text.TextUtils;
23 | import android.util.AttributeSet;
24 | import android.view.LayoutInflater;
25 | import android.widget.Button;
26 | import android.widget.FrameLayout;
27 | import android.widget.ImageView;
28 | import android.widget.RatingBar;
29 | import android.widget.TextView;
30 |
31 | import androidx.annotation.Nullable;
32 | import androidx.annotation.RequiresApi;
33 | import androidx.constraintlayout.widget.ConstraintLayout;
34 |
35 | import com.google.admob_advanced_native_recyvlerview.R;
36 | import com.google.android.gms.ads.nativead.MediaView;
37 | import com.google.android.gms.ads.nativead.NativeAd;
38 | import com.google.android.gms.ads.nativead.NativeAdView;
39 |
40 |
41 | /** Base class for a template view. * */
42 | public class TemplateView extends FrameLayout {
43 |
44 | private int templateType;
45 | private NativeTemplateStyle styles;
46 | private NativeAd nativeAd;
47 | private NativeAdView nativeAdView;
48 |
49 | private TextView primaryView;
50 | private TextView secondaryView;
51 | private RatingBar ratingBar;
52 | private TextView tertiaryView;
53 | private ImageView iconView;
54 | private MediaView mediaView;
55 | private Button callToActionView;
56 | private ConstraintLayout background;
57 |
58 | private static final String MEDIUM_TEMPLATE = "medium_template";
59 | private static final String SMALL_TEMPLATE = "small_template";
60 |
61 | public TemplateView(Context context) {
62 | super(context);
63 | }
64 |
65 | public TemplateView(Context context, @Nullable AttributeSet attrs) {
66 | super(context, attrs);
67 | initView(context, attrs);
68 | }
69 |
70 | public TemplateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
71 | super(context, attrs, defStyleAttr);
72 | initView(context, attrs);
73 | }
74 |
75 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
76 | public TemplateView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
77 | super(context, attrs, defStyleAttr, defStyleRes);
78 | initView(context, attrs);
79 | }
80 |
81 | public void setStyles(NativeTemplateStyle styles) {
82 | this.styles = styles;
83 | this.applyStyles();
84 | }
85 |
86 | public NativeAdView getNativeAdView() {
87 | return nativeAdView;
88 | }
89 |
90 | private void applyStyles() {
91 |
92 | Drawable mainBackground = styles.getMainBackgroundColor();
93 | if (mainBackground != null) {
94 | background.setBackground(mainBackground);
95 | if (primaryView != null) {
96 | primaryView.setBackground(mainBackground);
97 | }
98 | if (secondaryView != null) {
99 | secondaryView.setBackground(mainBackground);
100 | }
101 | if (tertiaryView != null) {
102 | tertiaryView.setBackground(mainBackground);
103 | }
104 | }
105 |
106 | Typeface primary = styles.getPrimaryTextTypeface();
107 | if (primary != null && primaryView != null) {
108 | primaryView.setTypeface(primary);
109 | }
110 |
111 | Typeface secondary = styles.getSecondaryTextTypeface();
112 | if (secondary != null && secondaryView != null) {
113 | secondaryView.setTypeface(secondary);
114 | }
115 |
116 | Typeface tertiary = styles.getTertiaryTextTypeface();
117 | if (tertiary != null && tertiaryView != null) {
118 | tertiaryView.setTypeface(tertiary);
119 | }
120 |
121 | Typeface ctaTypeface = styles.getCallToActionTextTypeface();
122 | if (ctaTypeface != null && callToActionView != null) {
123 | callToActionView.setTypeface(ctaTypeface);
124 | }
125 |
126 | int primaryTypefaceColor = styles.getPrimaryTextTypefaceColor();
127 | if (primaryTypefaceColor > 0 && primaryView != null) {
128 | primaryView.setTextColor(primaryTypefaceColor);
129 | }
130 |
131 | int secondaryTypefaceColor = styles.getSecondaryTextTypefaceColor();
132 | if (secondaryTypefaceColor > 0 && secondaryView != null) {
133 | secondaryView.setTextColor(secondaryTypefaceColor);
134 | }
135 |
136 | int tertiaryTypefaceColor = styles.getTertiaryTextTypefaceColor();
137 | if (tertiaryTypefaceColor > 0 && tertiaryView != null) {
138 | tertiaryView.setTextColor(tertiaryTypefaceColor);
139 | }
140 |
141 | int ctaTypefaceColor = styles.getCallToActionTypefaceColor();
142 | if (ctaTypefaceColor > 0 && callToActionView != null) {
143 | callToActionView.setTextColor(ctaTypefaceColor);
144 | }
145 |
146 | float ctaTextSize = styles.getCallToActionTextSize();
147 | if (ctaTextSize > 0 && callToActionView != null) {
148 | callToActionView.setTextSize(ctaTextSize);
149 | }
150 |
151 | float primaryTextSize = styles.getPrimaryTextSize();
152 | if (primaryTextSize > 0 && primaryView != null) {
153 | primaryView.setTextSize(primaryTextSize);
154 | }
155 |
156 | float secondaryTextSize = styles.getSecondaryTextSize();
157 | if (secondaryTextSize > 0 && secondaryView != null) {
158 | secondaryView.setTextSize(secondaryTextSize);
159 | }
160 |
161 | float tertiaryTextSize = styles.getTertiaryTextSize();
162 | if (tertiaryTextSize > 0 && tertiaryView != null) {
163 | tertiaryView.setTextSize(tertiaryTextSize);
164 | }
165 |
166 | Drawable ctaBackground = styles.getCallToActionBackgroundColor();
167 | if (ctaBackground != null && callToActionView != null) {
168 | callToActionView.setBackground(ctaBackground);
169 | }
170 |
171 | Drawable primaryBackground = styles.getPrimaryTextBackgroundColor();
172 | if (primaryBackground != null && primaryView != null) {
173 | primaryView.setBackground(primaryBackground);
174 | }
175 |
176 | Drawable secondaryBackground = styles.getSecondaryTextBackgroundColor();
177 | if (secondaryBackground != null && secondaryView != null) {
178 | secondaryView.setBackground(secondaryBackground);
179 | }
180 |
181 | Drawable tertiaryBackground = styles.getTertiaryTextBackgroundColor();
182 | if (tertiaryBackground != null && tertiaryView != null) {
183 | tertiaryView.setBackground(tertiaryBackground);
184 | }
185 |
186 | invalidate();
187 | requestLayout();
188 | }
189 |
190 | private boolean adHasOnlyStore(NativeAd nativeAd) {
191 | String store = nativeAd.getStore();
192 | String advertiser = nativeAd.getAdvertiser();
193 | return !TextUtils.isEmpty(store) && TextUtils.isEmpty(advertiser);
194 | }
195 |
196 | public void setNativeAd(NativeAd nativeAd) {
197 | this.nativeAd = nativeAd;
198 |
199 | String store = nativeAd.getStore();
200 | String advertiser = nativeAd.getAdvertiser();
201 | String headline = nativeAd.getHeadline();
202 | String body = nativeAd.getBody();
203 | String cta = nativeAd.getCallToAction();
204 | Double starRating = nativeAd.getStarRating();
205 | NativeAd.Image icon = nativeAd.getIcon();
206 |
207 | String secondaryText;
208 |
209 | nativeAdView.setCallToActionView(callToActionView);
210 | nativeAdView.setHeadlineView(primaryView);
211 | nativeAdView.setMediaView(mediaView);
212 | secondaryView.setVisibility(VISIBLE);
213 | if (adHasOnlyStore(nativeAd)) {
214 | nativeAdView.setStoreView(secondaryView);
215 | secondaryText = store;
216 | } else if (!TextUtils.isEmpty(advertiser)) {
217 | nativeAdView.setAdvertiserView(secondaryView);
218 | secondaryText = advertiser;
219 | } else {
220 | secondaryText = "";
221 | }
222 |
223 | primaryView.setText(headline);
224 | callToActionView.setText(cta);
225 |
226 | // Set the secondary view to be the star rating if available.
227 | if (starRating != null && starRating > 0) {
228 | secondaryView.setVisibility(GONE);
229 | ratingBar.setVisibility(VISIBLE);
230 | ratingBar.setMax(5);
231 | nativeAdView.setStarRatingView(ratingBar);
232 | } else {
233 | secondaryView.setText(secondaryText);
234 | secondaryView.setVisibility(VISIBLE);
235 | ratingBar.setVisibility(GONE);
236 | }
237 |
238 | if (icon != null) {
239 | iconView.setVisibility(VISIBLE);
240 | iconView.setImageDrawable(icon.getDrawable());
241 | } else {
242 | iconView.setVisibility(GONE);
243 | }
244 |
245 | if (tertiaryView != null) {
246 | tertiaryView.setText(body);
247 | nativeAdView.setBodyView(tertiaryView);
248 | }
249 |
250 | nativeAdView.setNativeAd(nativeAd);
251 | }
252 |
253 | /**
254 | * To prevent memory leaks, make sure to destroy your ad when you don't need it anymore. This
255 | * method does not destroy the template view.
256 | * https://developers.google.com/admob/android/native-unified#destroy_ad
257 | */
258 | public void destroyNativeAd() {
259 | nativeAd.destroy();
260 | }
261 |
262 | public String getTemplateTypeName() {
263 | if (templateType == R.layout.gnt_custom_small_template_view) {
264 | return MEDIUM_TEMPLATE;
265 | } else if (templateType == R.layout.gnt_small_template_view) {
266 | return SMALL_TEMPLATE;
267 | }
268 | return "";
269 | }
270 |
271 | private void initView(Context context, AttributeSet attributeSet) {
272 |
273 | TypedArray attributes =
274 | context.getTheme().obtainStyledAttributes(attributeSet, R.styleable.TemplateView, 0, 0);
275 |
276 | try {
277 | templateType =
278 | attributes.getResourceId(
279 | R.styleable.TemplateView_gnt_template_type, R.layout.gnt_custom_small_template_view);
280 | } finally {
281 | attributes.recycle();
282 | }
283 | LayoutInflater inflater =
284 | (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
285 | inflater.inflate(templateType, this);
286 | }
287 |
288 | @Override
289 | public void onFinishInflate() {
290 | super.onFinishInflate();
291 | nativeAdView = findViewById(R.id.native_ad_view);
292 | primaryView = findViewById(R.id.primary);
293 | secondaryView = findViewById(R.id.secondary);
294 | tertiaryView = findViewById(R.id.body);
295 |
296 | ratingBar = findViewById(R.id.rating_bar);
297 | ratingBar.setEnabled(false);
298 |
299 | callToActionView = findViewById(R.id.cta);
300 | iconView = findViewById(R.id.icon);
301 | mediaView = findViewById(R.id.media_view);
302 | background = findViewById(R.id.background);
303 | }
304 | }
305 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/java/com/google/rvadapter/AdmobNativeAdAdapter.java:
--------------------------------------------------------------------------------
1 | package com.google.rvadapter;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.LinearLayout;
9 |
10 | import androidx.annotation.IdRes;
11 | import androidx.annotation.LayoutRes;
12 | import androidx.recyclerview.widget.GridLayoutManager;
13 | import androidx.recyclerview.widget.RecyclerView;
14 |
15 | import com.google.admob_advanced_native_recyvlerview.R;
16 | import com.google.android.gms.ads.AdListener;
17 | import com.google.android.gms.ads.AdLoader;
18 | import com.google.android.gms.ads.AdRequest;
19 | import com.google.android.gms.ads.nativead.NativeAdOptions;
20 | import com.google.nativetemplates.NativeTemplateStyle;
21 | import com.google.nativetemplates.TemplateView;
22 |
23 | /**
24 | * Created by thuanle on 2/12/17.
25 | */
26 | public class AdmobNativeAdAdapter extends RecyclerViewAdapterWrapper {
27 |
28 | private static final int TYPE_FB_NATIVE_ADS = 900;
29 | private static final int DEFAULT_AD_ITEM_INTERVAL = 4;
30 |
31 | private final Param mParam;
32 |
33 | private AdmobNativeAdAdapter(Param param) {
34 | super(param.adapter);
35 | this.mParam = param;
36 |
37 | assertConfig();
38 | setSpanAds();
39 | }
40 |
41 | private void assertConfig() {
42 | if (mParam.gridLayoutManager != null) {
43 | //if user set span ads
44 | int nCol = mParam.gridLayoutManager.getSpanCount();
45 | if (mParam.adItemInterval % nCol != 0) {
46 | throw new IllegalArgumentException(String.format("The adItemInterval (%d) is not divisible by number of columns in GridLayoutManager (%d)", mParam.adItemInterval, nCol));
47 | }
48 | }
49 | }
50 |
51 | private int convertAdPosition2OrgPosition(int position) {
52 |
53 | return position - (position + 1) / (mParam.adItemInterval + 1);
54 | }
55 |
56 | @Override
57 | public int getItemCount() {
58 | int realCount = super.getItemCount();
59 | return realCount + realCount / mParam.adItemInterval;
60 | }
61 |
62 | @Override
63 | public int getItemViewType(int position) {
64 | if (isAdPosition(position)) {
65 | return TYPE_FB_NATIVE_ADS;
66 | }
67 | return super.getItemViewType(convertAdPosition2OrgPosition(position));
68 | }
69 |
70 | private boolean isAdPosition(int position) {
71 | /*if(position==1|| position==4)return true;*/
72 | return (position + 1) % (mParam.adItemInterval + 1) == 0;
73 | }
74 | public static final boolean isValidPhoneNumber(CharSequence target) {
75 | if (target.length()!=10) {
76 | return false;
77 | } else {
78 | return android.util.Patterns.PHONE.matcher(target).matches();
79 | }
80 | }
81 | private void onBindAdViewHolder(final RecyclerView.ViewHolder holder) {
82 | final AdViewHolder adHolder = (AdViewHolder) holder;
83 | if (mParam.forceReloadAdOnBind || !adHolder.loaded) {
84 | AdLoader adLoader = new AdLoader.Builder(adHolder.getContext(), mParam.admobNativeId)
85 | .forNativeAd(NativeAd -> {
86 | /*NativeTemplateStyle styles = new
87 | NativeTemplateStyle.Builder().withMainBackgroundColor().build();*/
88 |
89 | //adHolder.template.setStyles(styles);
90 |
91 | Log.e("admobnative","loaded");
92 | NativeTemplateStyle.Builder builder=new NativeTemplateStyle.Builder();
93 | builder.withPrimaryTextSize(11f);
94 | builder.withSecondaryTextSize(10f);
95 | builder.withTertiaryTextSize(06f);
96 | builder.withCallToActionTextSize(11f);
97 |
98 |
99 | if(mParam.layout==0){
100 | adHolder.templatesmall.setVisibility(View.VISIBLE);
101 | adHolder.templatesmall.setStyles(builder.build());
102 | adHolder.templatesmall.setNativeAd(NativeAd);
103 | }
104 | else if(mParam.layout==1){
105 | adHolder.templatemedium.setVisibility(View.VISIBLE);
106 | adHolder.templatemedium.setStyles(builder.build());
107 | adHolder.templatemedium.setNativeAd(NativeAd);
108 | }
109 | else {
110 | adHolder.templatecustom.setVisibility(View.VISIBLE);
111 | adHolder.templatecustom.setStyles(builder.build());
112 | adHolder.templatecustom.setNativeAd(NativeAd);
113 | }
114 |
115 | adHolder.loaded=true;
116 |
117 | })
118 | .withAdListener(new AdListener() {
119 | @Override
120 | public void onAdFailedToLoad(int errorCode) {
121 | Log.e("admobnative","error:"+errorCode);
122 | adHolder.adContainer.setVisibility(View.GONE);
123 | // Handle the failure by logging, altering the UI, and so on.
124 |
125 | }
126 | })
127 | .withNativeAdOptions(new NativeAdOptions.Builder()
128 | // Methods in the NativeAdOptions.Builder class can be
129 | // used here to specify individual options settings.
130 | .build())
131 | .build();
132 | adLoader.loadAd(new AdRequest.Builder().build());
133 | }
134 | }
135 |
136 | @Override
137 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
138 | if (getItemViewType(position) == TYPE_FB_NATIVE_ADS) {
139 | onBindAdViewHolder(holder);
140 | } else {
141 | super.onBindViewHolder(holder, convertAdPosition2OrgPosition(position));
142 | }
143 | }
144 |
145 | private RecyclerView.ViewHolder onCreateAdViewHolder(ViewGroup parent) {
146 | LayoutInflater inflater = LayoutInflater.from(parent.getContext());
147 | View adLayoutOutline = inflater
148 | .inflate(mParam.itemContainerLayoutRes, parent, false);
149 | ViewGroup vg = adLayoutOutline.findViewById(mParam.itemContainerId);
150 |
151 | LinearLayout adLayoutContent = (LinearLayout) inflater
152 | .inflate(R.layout.item_admob_native_ad, parent, false);
153 | vg.addView(adLayoutContent);
154 | return new AdViewHolder(adLayoutOutline);
155 | }
156 |
157 | @Override
158 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
159 | if (viewType == TYPE_FB_NATIVE_ADS) {
160 | return onCreateAdViewHolder(parent);
161 | }
162 | return super.onCreateViewHolder(parent, viewType);
163 | }
164 |
165 | private void setSpanAds() {
166 | if (mParam.gridLayoutManager == null) {
167 | return ;
168 | }
169 | final GridLayoutManager.SpanSizeLookup spl = mParam.gridLayoutManager.getSpanSizeLookup();
170 | mParam.gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
171 | @Override
172 | public int getSpanSize(int position) {
173 | if (isAdPosition(position)){
174 | return spl.getSpanSize(position);
175 | }
176 | return 1;
177 | }
178 | });
179 | }
180 |
181 | private static class Param {
182 | String admobNativeId;
183 | RecyclerView.Adapter adapter;
184 | int adItemInterval;
185 | boolean forceReloadAdOnBind;
186 |
187 | int layout;
188 |
189 | @LayoutRes
190 | int itemContainerLayoutRes;
191 |
192 | @IdRes
193 | int itemContainerId;
194 |
195 | GridLayoutManager gridLayoutManager;
196 | }
197 |
198 | public static class Builder {
199 | private final Param mParam;
200 |
201 | private Builder(Param param) {
202 | mParam = param;
203 | }
204 |
205 | public static Builder with(String placementId, RecyclerView.Adapter wrapped, String layout) {
206 | Param param = new Param();
207 | param.admobNativeId = placementId;
208 | param.adapter = wrapped;
209 |
210 |
211 | if(layout.toLowerCase().equals("small")){
212 | param.layout=0;
213 | }
214 |
215 | else if(layout.toLowerCase().equals("medium")){
216 |
217 | param.layout=1;
218 | }
219 | else {
220 | param.layout=2;
221 |
222 | }
223 |
224 | //default value
225 | param.adItemInterval = DEFAULT_AD_ITEM_INTERVAL;
226 | param.itemContainerLayoutRes = R.layout.item_admob_native_ad_outline;
227 | param.itemContainerId = R.id.ad_container;
228 | param.forceReloadAdOnBind = true;
229 | return new Builder(param);
230 | }
231 |
232 | public Builder adItemInterval(int interval) {
233 | mParam.adItemInterval = interval;
234 | return this;
235 | }
236 |
237 | public Builder adLayout(@LayoutRes int layoutContainerRes, @IdRes int itemContainerId) {
238 | mParam.itemContainerLayoutRes = layoutContainerRes;
239 | mParam.itemContainerId = itemContainerId;
240 | return this;
241 | }
242 |
243 | public AdmobNativeAdAdapter build() {
244 | return new AdmobNativeAdAdapter(mParam);
245 | }
246 |
247 | public Builder enableSpanRow(GridLayoutManager layoutManager) {
248 | mParam.gridLayoutManager = layoutManager;
249 | return this;
250 | }
251 | public Builder adItemIterval(int i) {
252 | mParam.adItemInterval=i;
253 | return this;
254 | }
255 |
256 | public Builder forceReloadAdOnBind(boolean forced) {
257 | mParam.forceReloadAdOnBind = forced;
258 | return this;
259 | }
260 | }
261 |
262 | private static class AdViewHolder extends RecyclerView.ViewHolder {
263 |
264 | TemplateView templatesmall,templatemedium,templatecustom;
265 | LinearLayout adContainer;
266 | boolean loaded;
267 | AdViewHolder(View view) {
268 | super(view);
269 | templatesmall=view.findViewById(R.id.my_templatesmall);
270 | templatecustom=view.findViewById(R.id.my_templatecustom);
271 | templatemedium=view.findViewById(R.id.my_templatemedium);
272 | loaded = false;
273 | adContainer=(LinearLayout)view.findViewById(R.id.native_ad_container);
274 | }
275 |
276 | Context getContext() {
277 | return adContainer.getContext();
278 | }
279 | }
280 | }
281 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/java/com/google/rvadapter/RecyclerViewAdapterWrapper.java:
--------------------------------------------------------------------------------
1 | package com.google.rvadapter;
2 |
3 | import android.view.ViewGroup;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.recyclerview.widget.RecyclerView;
7 |
8 |
9 | /**
10 | * @author rockerhieu on 7/6/15.
11 | */
12 | public class RecyclerViewAdapterWrapper extends RecyclerView.Adapter {
13 | private final RecyclerView.Adapter wrapped;
14 |
15 | public RecyclerViewAdapterWrapper(RecyclerView.Adapter wrapped) {
16 | this.wrapped = wrapped;
17 | this.wrapped.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
18 | public void onChanged() {
19 | notifyDataSetChanged();
20 | }
21 |
22 | public void onItemRangeChanged(int positionStart, int itemCount) {
23 | notifyItemRangeChanged(positionStart, itemCount);
24 | }
25 |
26 | public void onItemRangeInserted(int positionStart, int itemCount) {
27 | notifyItemRangeInserted(positionStart, itemCount);
28 | }
29 |
30 | public void onItemRangeRemoved(int positionStart, int itemCount) {
31 | notifyItemRangeRemoved(positionStart, itemCount);
32 | }
33 |
34 | public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
35 | notifyItemMoved(fromPosition, toPosition);
36 | }
37 | });
38 | }
39 |
40 | @NonNull
41 | @Override
42 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
43 | return wrapped.onCreateViewHolder(parent, viewType);
44 | }
45 |
46 | @Override
47 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
48 | wrapped.onBindViewHolder(holder, position);
49 | }
50 |
51 | @Override
52 | public int getItemCount() {
53 | return wrapped.getItemCount();
54 | }
55 |
56 | @Override
57 | public int getItemViewType(int position) {
58 | return wrapped.getItemViewType(position);
59 | }
60 |
61 | @Override
62 | public void setHasStableIds(boolean hasStableIds) {
63 | wrapped.setHasStableIds(hasStableIds);
64 | }
65 |
66 | @Override
67 | public long getItemId(int position) {
68 | return wrapped.getItemId(position);
69 | }
70 |
71 | @Override
72 | public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
73 | wrapped.onViewRecycled(holder);
74 | }
75 |
76 | @Override
77 | public boolean onFailedToRecycleView(@NonNull RecyclerView.ViewHolder holder) {
78 | return wrapped.onFailedToRecycleView(holder);
79 | }
80 |
81 | @Override
82 | public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
83 | wrapped.onViewAttachedToWindow(holder);
84 | }
85 |
86 | @Override
87 | public void onViewDetachedFromWindow(@NonNull RecyclerView.ViewHolder holder) {
88 | wrapped.onViewDetachedFromWindow(holder);
89 | }
90 |
91 | @Override
92 | public void registerAdapterDataObserver(@NonNull RecyclerView.AdapterDataObserver observer) {
93 | wrapped.registerAdapterDataObserver(observer);
94 | }
95 |
96 | @Override
97 | public void unregisterAdapterDataObserver(@NonNull RecyclerView.AdapterDataObserver observer) {
98 | wrapped.unregisterAdapterDataObserver(observer);
99 | }
100 |
101 | @Override
102 | public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
103 | wrapped.onAttachedToRecyclerView(recyclerView);
104 | }
105 |
106 | @Override
107 | public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
108 | wrapped.onDetachedFromRecyclerView(recyclerView);
109 | }
110 |
111 | public RecyclerView.Adapter getWrappedAdapter() {
112 | return wrapped;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/drawable/ad_mark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vimalcvs/RecyclerView-Native-ads-Example/88b44dff1f4e696294a77c03b977ce71f9aa2cff/nativetemplates/src/main/res/drawable/ad_mark.png
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/drawable/bg_ad_btn_common.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/drawable/gnt_outline_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/layout/gnt_custom_small_template_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
11 |
12 |
18 |
33 |
48 |
62 |
74 |
75 |
93 |
94 |
105 |
121 |
122 |
123 |
140 |
141 |
142 |
160 |
161 |
162 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/layout/gnt_medium_template_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
12 |
23 |
24 |
35 |
36 |
46 |
56 |
57 |
74 |
75 |
86 |
97 |
98 |
116 |
117 |
128 |
144 |
145 |
162 |
163 |
164 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
205 |
206 |
222 |
223 |
224 |
225 |
226 |
227 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/layout/gnt_small_template_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
11 |
12 |
18 |
33 |
48 |
62 |
74 |
75 |
93 |
94 |
105 |
121 |
122 |
123 |
140 |
141 |
142 |
160 |
161 |
162 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/layout/item_admob_native_ad.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
23 |
24 |
25 |
31 |
32 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/layout/item_admob_native_ad_outline.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/values-night/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00F4F4F4
4 | #FDFDFE
5 | #808080
6 | #262937
7 | #FDFDFE
8 | #7E8A97
9 | #606770
10 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00F4F4F4
4 | #FDFDFE
5 | #808080
6 | #FAFBFB
7 | #000001
8 | #212121
9 | #606770
10 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | - 0.25
4 | 10dp
5 | 12sp
6 | 15sp
7 | 25dp
8 | 20dp
9 | 0dp
10 | 10sp
11 | 0dp
12 | 0dp
13 |
14 |
--------------------------------------------------------------------------------
/nativetemplates/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':nativetemplates'
2 | rootProject.name='AdmobAdvancedNativeRecyclerview'
3 |
--------------------------------------------------------------------------------