This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
binding.signInWithHuaweiButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
mHuaweiIdAuthParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM) | |
.setIdToken() | |
.setAccessToken() | |
.createParams(); | |
HuaweiIdAuthService mHuaweiIdAuthService = HuaweiIdAuthManager.getService (LoginActivity.this, mHuaweiIdAuthParams); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == REQUEST_SIGN_IN_LOGIN) { | |
HuaweiIdAuthResult result = HuaweiIdAuthAPIManager.HuaweiIdAuthAPIService.parseHuaweiIdFromIntent(data); | |
if (result != null) { | |
if (result.isSuccess()) { | |
// Obtain the authorization result. | |
//HuaweiIdAuthResult authResult = HuaweiIdAuthAPIManager.HuaweiIdAuthAPIService.parseHuaweiIdFromIntent(data); | |
Intent i = new Intent(getBaseContext(), MainActivity.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onStart() { | |
HuaweiIdAuthParams authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM).createParams(); | |
service = HuaweiIdAuthManager.getService(MainActivity.this, authParams); | |
Task<AuthHuaweiId> task = service.silentSignIn(); | |
task.addOnSuccessListener(new OnSuccessListener<AuthHuaweiId>() { | |
@Override | |
public void onSuccess(AuthHuaweiId userAccount) { | |
// Obtain the user's HUAWEI ID information. | |
binding.usernameTextView.setText(userAccount.getDisplayName()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//FROM HERE... | |
binding.signOutButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
signOutFromAccount(); | |
} | |
}); | |
//...TO HERE, SHOULD BE INSIDE ONCREATE() METHOD. A SIMPLE FUNCTION CALL. | |
//THIS IS A CUSTOM METHOD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onBackPressed() { | |
if(doubleBackToExitPressedOnce){ | |
Intent a = new Intent(Intent.ACTION_MAIN); | |
a.addCategory(Intent.CATEGORY_HOME); | |
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
startActivity(a); | |
} | |
else{ | |
Toast.makeText(this, "Please click again BACK to exit", Toast.LENGTH_SHORT).show(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressLint("StaticFieldLeak") | |
public void initializeManagerAndGetPlayList(final Context context) { | |
new AsyncTask<Void, Void, Void>() { | |
@Override | |
protected Void doInBackground(Void... voids) { | |
HwAudioPlayerConfig hwAudioPlayerConfig = new HwAudioPlayerConfig(context); | |
HwAudioManagerFactory.createHwAudioManager(hwAudioPlayerConfig, new HwAudioConfigCallBack() { | |
@RequiresApi(api = Build.VERSION_CODES.R) | |
@Override | |
public void onSuccess(HwAudioManager hwAudioManager) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<HwAudioPlayItem> getLocalPlayList(Context context) { | |
List<HwAudioPlayItem> playItemList = new ArrayList<>(); | |
Cursor cursor = null; | |
try { | |
ContentResolver contentResolver = context.getContentResolver(); | |
if (contentResolver == null) { | |
return playItemList; | |
} | |
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private List<HwAudioStatusListener> mTempListeners = new CopyOnWriteArrayList<>(); //a global variable | |
private void doListenersAndNotifications(final Context context) { | |
new Handler(Looper.getMainLooper()).post(new Runnable() { | |
@Override | |
public void run() { | |
for (HwAudioStatusListener listener : mTempListeners) { | |
try { | |
mHwAudioManager.addPlayerStatusListener(listener); | |
} catch (RemoteException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void addListener(HwAudioStatusListener listener) { | |
if (mHwAudioManager != null) { | |
try { | |
mHwAudioManager.addPlayerStatusListener(listener); | |
} catch (RemoteException e) { | |
Log.e("TAG", "TAG", e); | |
} | |
} else { | |
mTempListeners.add(listener); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Drawable drawablePlay = getDrawable(R.drawable.btn_playback_play_normal); | |
final Drawable drawablePause = getDrawable(R.drawable.btn_playback_pause_normal); | |
binding.playButtonImageView.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if(binding.playButtonImageView.getDrawable().getConstantState().equals(drawablePlay.getConstantState())){ | |
if (mHwAudioPlayerManager != null){ | |
mHwAudioPlayerManager.play(); | |
binding.playButtonImageView.setImageDrawable(getDrawable(R.drawable.btn_playback_pause_normal)); |
OlderNewer