Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Targeting SDK 34, migrated to version-catalog, few minor fixes. #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: set up JDK 1.8
uses: actions/setup-java@v1
# https://github.com/actions/setup-java
- name: Set up AWS Corretto JDK 17
uses: actions/setup-java@v4
with:
java-version: 1.8
distribution: corretto
java-version: '17'
architecture: x64
- name: Get latest code
uses: actions/checkout@v4
- name: Make Gradle executable
run: chmod +x ./gradlew
- name: Build with Gradle
Expand Down
14 changes: 1 addition & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,7 @@ captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
/.idea/

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
Expand Down Expand Up @@ -81,5 +71,3 @@ lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Used to obtain users' consent on the privacy statement.
## Running Result
Banner ads         Interstitial ads        Native ads

<img src="/result/Banner.gif" width=200> <img src="result/Interstitial.gif" width=200> <img src="result/Native.gif" width=200>
<img src="/result/Banner.gif" width=200> <img src="result/Interstitial.gif" width=200> <img src="result/Native.gif" width=200>

Reward ads&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp; Roll ads&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp; Splash ads

Expand Down
48 changes: 27 additions & 21 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
apply plugin: 'com.android.application'
plugins {
alias(libs.plugins.android.application)
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
namespace "com.huawei.hms.ads.sdk"
buildToolsVersion = "34.0.0"
compileSdk 34
defaultConfig {
applicationId "com.huawei.hms.ads.sdk"
minSdkVersion 19
targetSdkVersion 29
minSdk 19
targetSdk 34
versionCode 1
versionName "1.0"
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -19,21 +28,18 @@ android {
}
}

repositories {
flatDir {
dirs 'libs'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.huawei.hms:ads-lite:13.4.69.300'
implementation 'com.huawei.hms:ads-consent:3.4.69.300'
implementation 'com.huawei.hms:ads-omsdk:1.3.35'
implementation libs.androidx.appcompat
implementation libs.androidx.constraintlayout
implementation libs.huawei.hms.ads.lite
implementation libs.huawei.hms.ads.consent
implementation libs.huawei.hms.ads.omsdk

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
testImplementation libs.junit
debugImplementation libs.androidx.test.monitor
androidTestImplementation libs.androidx.test.core
androidTestImplementation libs.androidx.test.junit
androidTestImplementation libs.androidx.test.rules
androidTestImplementation libs.androidx.test.runner
androidTestImplementation libs.androidx.espresso.core
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class ExampleInstrumentedTest {
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("com.huawei.hms.ads.sdk", appContext.getPackageName());
}
}
46 changes: 22 additions & 24 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.hms.ads.sdk">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -10,56 +11,53 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
android:theme="@style/AppTheme">

<activity
android:name=".SplashActivity"
android:configChanges="orientation|screenSize"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:exported="false"
android:screenOrientation="portrait">
</activity>
android:exported="false"/>

<activity
android:name=".BannerActivity"
android:exported="false"
android:screenOrientation="portrait" />
android:exported="false"/>

<activity
android:name=".NativeActivity"
android:exported="false"
android:screenOrientation="portrait"/>
android:exported="false"/>

<activity
android:name=".RewardActivity"
android:exported="false"
android:screenOrientation="portrait" />
android:exported="false"/>

<activity
android:name=".InterstitialActivity"
android:exported="false"
android:screenOrientation="portrait" />
android:exported="false"/>

<activity
android:name=".InstreamActivity"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|touchscreen"
android:exported="false"
android:screenOrientation="portrait" />
android:exported="false"/>

<activity
android:name=".ProtocolActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />
android:exported="false"/>

<activity
android:name=".ConsentActivity"
android:exported="false"
android:screenOrientation="portrait" />
android:exported="false"/>

</application>

</manifest>
30 changes: 5 additions & 25 deletions app/src/main/java/com/huawei/hms/ads/sdk/AdFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,8 @@

package com.huawei.hms.ads.sdk;


public class AdFormat {
/**
* Item name
*/
private String title;

/**
* Target activity
*/
private Class targetClass;

public AdFormat(String title, Class<?> targetClass) {
this.title = title;
this.targetClass = targetClass;
}

public String getTitle() {
return title;
}

public Class getTargetClass() {
return targetClass;
}
}
/**
* @param title The items name
* @param targetClass Target activity's class
*/
public record AdFormat(String title, Class<?> targetClass) {}
15 changes: 10 additions & 5 deletions app/src/main/java/com/huawei/hms/ads/sdk/AdSampleAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,30 @@
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.List;

public class AdSampleAdapter extends ArrayAdapter<AdFormat> {
private Context mContext;
private final Context mContext;

private int resourceId;
private final int resourceId;

public AdSampleAdapter(Context context, int resource, List<AdFormat> formatList) {
super(context, resource, formatList);
mContext = context;
resourceId = resource;
}

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
AdFormat adFormat = getItem(position);
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View view = LayoutInflater.from(mContext).inflate(resourceId, parent, false);
TextView title = view.findViewById(android.R.id.text1);
title.setText(adFormat.getTitle());
AdFormat adFormat = getItem(position);
if (adFormat != null) {
title.setText(adFormat.title());
}
return view;
}
}
22 changes: 6 additions & 16 deletions app/src/main/java/com/huawei/hms/ads/sdk/AdsConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,18 @@

public class AdsConstant {

/**
* SharedPreferences name.
*/
/** SharedPreferences name. */
public static final String SP_NAME = "HuaweiAdsSdkSharedPreferences";

/**
* The SP key of protocol.
*/
/** The SP key of protocol. */
public static final String SP_PROTOCOL_KEY = "protocol";

/**
* The SP key of consent.
*/
/** The SP key of consent. */
public static final String SP_CONSENT_KEY = "consent";

/**
* The SP default value of protocol.
*/
/** The SP default value of protocol. */
public static final int DEFAULT_SP_PROTOCOL_VALUE = 0;

/**
* The SP default value of consent.
*/
/** The SP default value of consent. */
public static final int DEFAULT_SP_CONSENT_VALUE = -1;
}
}
Loading