gpt4 book ai didi

java - 我需要在代码中以不同的方法访问库命令

转载 作者:行者123 更新时间:2023-12-02 04:20:50 26 4
gpt4 key购买 nike

好吧,我会尽力让这件事变得尽可能简单,因为我一直对它感到困惑。所以我正在使用一个名为 AchievementUnlocked 的库,您可以在这里找到它 Github Link

所以,是的,我将发布下面的代码,但基本上我需要从 Activity 中的另一个方法访问下面的方法。

我需要访问的方法:

public void notification() {
int seconds = Integer.parseInt(duration);
notificationstatus = "ACTIVE";


final AchievementUnlocked achievementUnlocked = new AchievementUnlocked(MainActivity.this).setTitle(title).
setSubtitleColor(Color.parseColor(colortxt)).
setSubTitle(text).
setDuration(Settings.Time).
setBackgroundColor(Color.parseColor(colorbg)).
setTitleColor(Color.parseColor(colortxt)).
setIcon(getDrawableFromRes(image1)).
isLarge(Settings.largepref).build();

View iconIV = achievementUnlocked.getIconView();
ObjectAnimator outX = ObjectAnimator.ofFloat(iconIV, "scaleX", 0.9f, 0.7f);
ObjectAnimator outY = ObjectAnimator.ofFloat(iconIV, "scaleY", 0.9f, 0.7f);
ObjectAnimator inX = ObjectAnimator.ofFloat(iconIV, "scaleX", 0.7f, 0.9f);
ObjectAnimator inY = ObjectAnimator.ofFloat(iconIV, "scaleY", 0.7f, 0.9f);
final AnimatorSet Outset = new AnimatorSet();
final AnimatorSet Ani = new AnimatorSet();
final AnimatorSet Inset = new AnimatorSet();
outX.setDuration(1000);
outY.setDuration(1000);
inX.setDuration(1000);
inY.setDuration(1000);
Ani.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
Ani.start();
}
});
Outset.playTogether(outX, outY);
Inset.playTogether(inX, inY);
(achievementUnlocked.getAchievementView()).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
achievementUnlocked.dismiss();
NotificationService.run();
}
});
achievementUnlocked.getAchievementView().setOnTouchListener(gestureListener);


Ani.play(Outset).before(Inset);
achievementUnlocked.setAchievementListener(new AchievementUnlocked.achievementListener() {
@Override
public void onAchievementBeingCreated(AchievementUnlocked achievement, boolean created) {

}

@Override
public void onAchievementExpanding(AchievementUnlocked achievement, boolean expanded) {
if (expanded) Ani.start();

}

@Override
public void onAchievementShrinking(AchievementUnlocked achievement, boolean shrunken) {
if (!shrunken) {
if (Ani.isRunning())
Ani.cancel();
notificationstatus = "UNACTIVE";
Log.i("Status Set UNACTIVE", notificationstatus);
}


}

@Override
public void onAchievementBeingDestroyed(AchievementUnlocked achievement, boolean destroyed) {

}
});

achievementUnlocked.show();

}

我需要从这部分代码访问该方法:

class MyGestureDetector extends GestureDetector.SimpleOnGestureListener    {

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// left to right swipe
if(e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
**Rightswipe();**
}
// right to left swipe
else if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
**Leftswipe();**
}
} catch (Exception e) {
// nothing
}
return false;
}



}

所以我的主要问题是我如何表现得像在第二个方法的原始方法中一样,因为函数 achievementUnlocked.dismiss(); 在您看到的主方法之外无法访问第一的 。我真的很感谢任何帮助!

最佳答案

MyGestureDetector 添加一个 setter ,该 setter 采用 AchievementUnlocked 作为参数。将 AchievementUnlocked 存储在 MyGestureDetector 的字段中。从 notification() 调用该 setter。然后,MyGestureDetector 可以访问 AchievementUnlocked 实例,并可以对其调用 dismiss()

关于java - 我需要在代码中以不同的方法访问库命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32792197/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com