0
好吧,我要儘可能簡化這個過程,因爲我一直在想它。所以我使用一個名爲AchievementUnlocked的庫,你可以在這裏找到Github Link我需要在我的代碼中以不同的方法訪問庫命令
所以是的,我會發佈下面的代碼,但基本上我需要從我的活動中的另一種方法訪問下面的方法。
方法,我需要訪問:
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();
不能在您首先看到的主要方法之外訪問。我非常感謝任何幫助!
因此,無論如何,你可以發佈這樣的示例代碼,因爲這一切聽起來超級外國給我?對於Android編碼和日常學習,我真的很陌生,因爲StackOverflow!這些超級有用的新東西! :) –
@SkylerMartin:嗯,領域,制定者,等等*非常*基本的Java。請參閱[此鏈接](http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html)以獲取關於字段,獲取者和設置者的討論。在'Bicycle'示例類中,'cadence'是一個字段的例子,'getCadence()'是一個getter方法的例子,'setCadence()'是一個setter方法的例子。 – CommonsWare
我瞭解它的超級基本概念,但我的意思是,如果您知道自己在做什麼,並且可以將其適用於我的代碼,我將很樂意爲您付款! –