Skip to content

Instantly share code, notes, and snippets.

@melikeeroglu
melikeeroglu / AccountSignIn.cs
Last active September 28, 2020 13:25
Unity account kit
using HuaweiMobileServices.Id;
using HuaweiMobileServices.Utils;
using UnityEngine;
using UnityEngine.UI;
using HmsPlugin;
using UnityEngine.SceneManagement;
public class AccountSignIn : MonoBehaviour
{
private const string NOT_LOGGED_IN = "No user logged in";
@melikeeroglu
melikeeroglu / build.gradle
Created September 30, 2020 06:03
HiAnimals app build.gradle
buildscript {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
// NOTE: Do not place your application dependencies here; they belong
@melikeeroglu
melikeeroglu / AppMarketActivity
Created September 30, 2020 06:06
HiAnimals AppMarketActivity
package com.team3.animalsintroduction.common;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@melikeeroglu
melikeeroglu / insertPhoto
Created September 30, 2020 06:08
HiAnimals InsertPhoto
public void insertPhoto(Photo photo) {
state = false;
if (mCloudDBZone == null) {
Log.w(Constant.DB_ZONE_WRAPPER, "INSERT Photo : CloudDBZone is null, try re-open it");
return;
}
CloudDBZoneTask<Integer> upsertTask = mCloudDBZone.executeUpsert(photo);
if (mUiCallBack == null) {
return;
}
@melikeeroglu
melikeeroglu / getAllPhotos
Created September 30, 2020 06:09
HiAnimals getAllPhotos
public void getAllPhotos(Context mContext) {
if (mCloudDBZone == null) {
Log.w(Constant.DB_ZONE_WRAPPER, "GET USER DETAIL : CloudDBZone is null, try re-open it");
return;
}
SharedPreferences pref = mContext.getSharedPreferences("MyPref", mContext.MODE_PRIVATE);
String token = pref.getString("token",null);
CloudDBZoneTask<CloudDBZoneSnapshot<Photo>> queryTask = mCloudDBZone.executeQuery(
CloudDBZoneQuery.where(Photo.class).orderByDesc("id").equalTo("token",token ).limit(1),
CloudDBZoneQuery.CloudDBZoneQueryPolicy.POLICY_QUERY_FROM_CLOUD_ONLY);
@melikeeroglu
melikeeroglu / onAddOrQueryPhoto
Created September 30, 2020 06:10
HiAnimals onAddOrQueryPhoto
@Override
public void onAddOrQueryPhoto(List<Photo> photoList) {
photo = photoList.get(0);
Intent intent = new Intent(AnimalActivity.this, PhotoActivity.class);
//creates the temporary file and gets the path
Bitmap bitmap = BitmapFactory.decodeByteArray(photo.getPhoto(), 0, photo.getPhoto().length);
String filePath= tempFileImage(this,bitmap,"name");
//passes the file path string with the intent
intent.putExtra("path", filePath);
loadinPanel.setVisibility(View.GONE);
@melikeeroglu
melikeeroglu / onActivityResult
Created September 30, 2020 06:12
HiAnimals onActivityResult
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1001) {
Task<AuthHuaweiId> authHuaweiIdTask = HuaweiIdAuthManager.parseAuthResultFromIntent(data);
if (authHuaweiIdTask.isSuccessful()) {
AuthHuaweiId huaweiAccount = authHuaweiIdTask.getResult();
Log.i(TAG, "signIn success Access Token = " + huaweiAccount.getAccessToken());
Log.i(TAG, "signIn success User Name = " + huaweiAccount.getDisplayName());
}
else {
@melikeeroglu
melikeeroglu / transmitTokenIntoAppGalleryConnect
Last active September 30, 2020 06:14
HiAnimals transmitTokenIntoAppGalleryConnect
private void transmitTokenIntoAppGalleryConnect(String accessToken) {
AGConnectAuthCredential credential = HwIdAuthProvider.credentialWithToken(accessToken);
AGConnectAuth.getInstance().signIn(credential).addOnSuccessListener(new OnSuccessListener<SignInResult>() {
@Override
public void onSuccess(SignInResult signInResult) {
startActivity(new Intent(MainActivity.this, HomePageActivity.class));
finish();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
@melikeeroglu
melikeeroglu / signInAnonymously
Created September 30, 2020 06:15
HiAnimals signInAnonymously
AGConnectAuth.getInstance().signInAnonymously().addOnSuccessListener(new OnSuccessListener<SignInResult>() {
@Override
public void onSuccess(SignInResult signInResult) {
startActivity(new Intent(MainActivity.this, HomePageActivity.class));
finish();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.d(TAG, "Error " + e);
@melikeeroglu
melikeeroglu / Initialize
Created September 30, 2020 06:15
Huawei Initialize Ads
// Initialize the HUAWEI Ads SDK.
HwAds.init(this);
// Call new BannerView(Context context) to create a BannerView class.
BannerView topBannerView = new BannerView(this);
topBannerView.setAdId(Constant.AD_ID);
topBannerView.setBannerAdSize(BannerAdSize.BANNER_SIZE_360_57);
topBannerView.loadAd(adParam);
ConstraintLayout rootView = findViewById(R.id.mainActivity);
rootView.addView(topBannerView);