Skip to content

Commit

Permalink
Merge pull request #85 from Explore-In-HMS/dev
Browse files Browse the repository at this point in the history
Phase 1 development released to master
  • Loading branch information
Feyzarkt authored Mar 20, 2024
2 parents b5a6bbd + a0be314 commit 68640ea
Show file tree
Hide file tree
Showing 47 changed files with 1,424 additions and 52 deletions.
37 changes: 9 additions & 28 deletions .github/workflows/debug_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,29 @@
## 1
name: Build Debug Apk and Deploy

## Actions that will be executed when pull request is created
on:
pull_request:
branches:
- master

jobs:
## Debug
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: 11
# 3
distribution: 'adopt'
# 3.1
- name: Clean Project
run: ./gradlew clean
# 3.2
- name: Generate Debug APK
run: ./gradlew assembleDebug --stacktrace

# 4
- name: Upload APK to artifacts
uses: actions/upload-artifact@master
uses: actions/upload-artifact@v3
with:
name: app-debug.apk
path: app/build/outputs/apk/debug/app-debug.apk

# deploy_To_Firebase
deploy-firebase:
# 1
needs: [ build ]
runs-on: ubuntu-latest
steps:
# 2
- uses: actions/download-artifact@master
with:
name: app-debug.apk
#3
- name: upload artifact to Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{secrets.FIREBASE_APP_ID}}
token: ${{secrets.FIREBASE_TOKEN}}
groups: debug-test
file: app-debug.apk
path: app/build/outputs/apk/debug/app-debug.apk
116 changes: 101 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,67 @@ If you want to contribute don't hesitate to create PR's :)

Currently added services: `MapKit`, `Location`, `Analytics`, `CreditCardScanner`, `Awareness`, `Scan`, `Translate`, `Speech To Text`, `Text To Speech`, `Object Detection`, `Text Recognition`, `Face Detection`, `Language Detection`, `Image Classification`, `Account`, `Auth`, `Safety`, `Crash`, `Push`, `Site`, `Identity` and `Remote Config`.

## How to install
## How to install

### Step 1. Add the JitPack repository, Huawei repo and classpaths to your build file
### Step 1. Add the dependency of Huawei AGC and Google Play Services to your build file
```gradle
buildscript {
repositories {
...
maven {url 'https://developer.huawei.com/repo/'}
ext {
toolsBuildGradleVersion = '7.1.1'
}
dependencies {
...
classpath 'com.huawei.agconnect:agcp:1.7.1.300'
classpath 'com.google.gms:google-services:4.3.14'
classpath "com.android.tools.build:gradle:$toolsBuildGradleVersion"
classpath 'com.huawei.agconnect:agcp:1.9.1.301'
classpath "io.realm:realm-gradle-plugin:10.13.3-transformer-api"
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
}
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
maven { url "https://developer.huawei.com/repo/" }
}
plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
id 'com.google.gms.google-services' version '4.4.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
```
### Step 2. Get the agconnect-services.json file from the AGC Console and google-services.json file from Firebase Console. Then, place it under the app module. And, add plugins to app level gradle file header.
```gradle
apply plugin: 'com.huawei.agconnect'
apply plugin: 'com.google.gms.google-services'
```
### Step 3. Add the dependency for module(s):
### Step 3. Add the dependency to app level gradle file:
```gradle
dependencies {
implementation(platform("com.google.firebase:firebase-bom:32.5.0"))
implementation 'com.huawei.agconnect:agconnect-core:1.9.1.300'
implementation 'com.huawei.hms:hmscoreinstaller:6.11.0.301'
}
```
### Step 4. Add the JitPack and Huawei developer repository to settings.gradle:
```gradle
pluginManagement {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
}
}
dependencyResolutionManagement {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
maven { url "https://jitpack.io" }
}
}
```
### Step 5. Add the this configuration setting that disables the instrumentation of the application performance management system:
```gradle
apmsInstrumentationEnabled=false
```
### Step 6. Add the dependency for module(s):
com.github.Explore-In-HMS.common-mobile-services

`latest version 2.2.2`
Expand Down Expand Up @@ -88,6 +119,12 @@ implementation 'com.github.Explore-In-HMS.common-mobile-services:objectdetection
### Text Recognition
```gradle
implementation 'com.github.Explore-In-HMS.common-mobile-services:textrecognition:<versionName>'
```
### Ads
```gradle
implementation 'com.github.Explore-In-HMS.common-mobile-services:ads:<versionName>'
implementation 'com.google.android.gms:play-services-ads:22.2.0'
implementation 'com.huawei.hms:ads-prime:3.4.62.302'
```
### Face Detection
```gradle
Expand Down Expand Up @@ -893,6 +930,55 @@ The `textRecognition()` function takes a callback lambda function as a parameter
fun textRecognition(bitmap: Bitmap, callback: (recognizedValue: RecognitionResult<Any>) -> Unit)
```
## Ads
Allows you to show ads in your app.
### Rewarded Ad
Rewarded ads are shown to users in exchange for a reward, such as an extra life or in-app currency.
You can specify the reward values associated with the ad units in your app and set different rewards for different ad units. Users will receive the reward for interacting with the ad without needing to install anything.
#### How to use
Create an IRewardedAd variable in order to get instance when ads showing is ready.
```kt
private lateinit var rewardedAd: IRewardedAd
```
First, you need to call static 'load()' function to get rewarded ad instance.
By passing 'context', 'hmsAd_ID', 'gmsAd_ID' and 'RewardedAdLoadCallback' you will get IRewardedAd instance in order to show ad.
```kt
RewardedAd.load(
this,
"testx9dtjwj8hp",
"ca-app-pub-3940256099942544/5224354917",
object : RewardedAdLoadCallback {
override fun onAdLoadFailed(adError: String) {
Log.e("main", adError)
}
override fun onRewardedAdLoaded(rewardedAd: IRewardedAd) {
rewardedAd = rewardedAd
}
}
)
```
Call `show()` function whenever you want to show ad.
You need to pass 'context' and 'UserRewardEarnedListener' params in order to get reward after user watched the ad.
You can get reward value by calling 'getAmount()' function.
```kt
rewardedAd.show(
this,
object : UserRewardEarnedListener {
override fun onUserEarnedReward(item: IRewardItem) {
Log.d("main", "${item.getAmount()} ${item.getTypeOrName()}")
}
}
)
```
In Addition you need add your ca-app-pub value in androidmanifest.xml
```xml
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-YOUR-CA_APP_PUB_HERE" />
```
## Face Detection
With ML Kit's face detection API, you can detect faces in an image, identify key facial features, and get the contours of detected faces. Note that the API detects faces, it does not recognize people. With face detection, you can get the information you need to perform tasks like embellishing selfies and portraits, or generating avatars from a user's photo. Because ML Kit can perform face detection in real time, you can use it in applications like video chat or games that respond to the player's expressions.

Expand Down
1 change: 1 addition & 0 deletions ads/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
7 changes: 7 additions & 0 deletions ads/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apply from: "$project.rootDir/base_sdk.gradle"

dependencies {
implementation 'com.google.android.gms:play-services-ads:22.2.0'
implementation 'com.huawei.hms:ads-prime:3.4.62.302'
api project(':core')
}
Empty file added ads/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions ads/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
6 changes: 6 additions & 0 deletions ads/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hms.lib.commonmobileservices.ads">

<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2020. Explore in HMS. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.hms.lib.commonmobileservices.ads.banner

import android.content.Context
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.LoadAdError
import com.hms.lib.commonmobileservices.ads.banner.common.BannerAdLoadCallback
import com.hms.lib.commonmobileservices.ads.banner.factory.BannerAdFactory
import com.hms.lib.commonmobileservices.ads.banner.implementation.GoogleBannerAd
import com.hms.lib.commonmobileservices.ads.banner.implementation.HuaweiBannerAd
import com.hms.lib.commonmobileservices.core.Device
import com.hms.lib.commonmobileservices.core.MobileServiceType
import com.huawei.hms.ads.AdListener
import com.huawei.hms.ads.AdParam
import com.huawei.hms.ads.banner.BannerView

class BannerAd {

companion object {
/**
* Loads a banner ad based on the mobile service type.
*
* @param context The context of the application.
* @param gms_AdView The Google Mobile Services AdView.
* @param hms_BannerView The Huawei Mobile Services BannerView.
* @param gmsAdRequestParams The Google Mobile Services AdRequest parameters. Default is null.
* @param hmsAdRequestParams The Huawei Mobile Services AdParam parameters. Default is null.
* @param callback The callback for banner ad loading events.
* @throws IllegalArgumentException if the mobile service type is not supported.
*/
fun load(
context: Context,
gms_AdView: AdView?,
hms_BannerView: BannerView?,
gmsAdRequestParams: AdRequest? = null,
hmsAdRequestParams: AdParam? = null,
callback: BannerAdLoadCallback
) {
when (Device.getMobileServiceType(context)) {
MobileServiceType.GMS -> {
val adRequestParams = gmsAdRequestParams ?: AdRequest.Builder().build()
gms_AdView?.apply {
adListener = object : com.google.android.gms.ads.AdListener() {
override fun onAdLoaded() {
super.onAdLoaded()
val googleBannerAdFactory =
BannerAdFactory.createFactory<GoogleBannerAd, AdView>(gms_AdView)
googleBannerAdFactory.create().let(callback::onBannerAdLoaded)
}

override fun onAdFailedToLoad(p0: LoadAdError) {
callback.onAdLoadFailed(p0.toString())
}
}
loadAd(adRequestParams)
}
}
MobileServiceType.HMS -> {
val adRequestParams = hmsAdRequestParams ?: AdParam.Builder().build()
hms_BannerView?.apply {
adListener = object : AdListener() {
override fun onAdLoaded() {
super.onAdLoaded()
val huaweiBannerAd =
BannerAdFactory.createFactory<HuaweiBannerAd, BannerView>(
hms_BannerView
)
huaweiBannerAd.create().let(callback::onBannerAdLoaded)
}

override fun onAdFailed(errorCode: Int) {
callback.onAdLoadFailed(errorCode.toString())
}
}
loadAd(adRequestParams)
}

}
MobileServiceType.NON -> throw IllegalArgumentException()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2020. Explore in HMS. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.hms.lib.commonmobileservices.ads.banner.common

import com.hms.lib.commonmobileservices.ads.banner.implementation.IBannerAd

interface BannerAdLoadCallback {
fun onAdLoadFailed(adError: String)
fun onBannerAdLoaded(bannerAd: IBannerAd)
}
Loading

0 comments on commit 68640ea

Please sign in to comment.