I want add a new key on port p1_6
cc2530EB, zstack2.3.0
#define HAL_KEY_SW_7_PORT P1
#define HAL_KEY_SW_7_BIT BV(6)
#define HAL_KEY_SW_7_SEL P1SEL
#define HAL_KEY_SW_7_DIR P1DIR
#define HAL_KEY_SW_7_EDGEBIT BV(2)
#define HAL_KEY_SW_7_EDGE HAL_KEY_FALLING_EDGE
#define HAL_KEY_SW_7_IEN IEN2 /* CPU interrupt mask register */
#define HAL_KEY_SW_7_IENBIT BV(4) /* Mask bit for all of Port_1 */
#define HAL_KEY_SW_7_ICTL P1IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_7_ICTLBIT BV(6) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_7_PXIFG P1IFG /* Interrupt flag at source */
actually , I copied the #defines from HAL_KEY_SW_6
but something changed
like #define HAL_KEY_SW_7_EDGEBIT BV(2) and #define HAL_KEY_SW_7_IENBIT BV(4)
I dont know why HAL_KEY_SW_7_IENBIT is BV(4) and HAL_KEY_SW_6_IENBIT is BV(5)
actually , I could not change these two defines, If I changed, the sw1 key (p0_1) and p1_6 wont work
anybody know why?
Now
in void HalKeyInit( void )
I also add
HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT); /* Set pin function to GPIO */
HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT); /* Set pin direction to Input */
in HalKeyConfig
PICTL &= ~(HAL_KEY_SW_7_EDGEBIT); /* Clear the edge bit */
/* For falling edge, the bit must be set. */
#if (HAL_KEY_SW_7_EDGE == HAL_KEY_FALLING_EDGE)
PICTL |= HAL_KEY_SW_7_EDGEBIT;
#endif
HAL_KEY_SW_7_ICTL |= HAL_KEY_SW_7_ICTLBIT;
HAL_KEY_SW_7_IEN |= HAL_KEY_SW_7_IENBIT;
HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT);
in HalKeyRead
//if (HAL_PUSH_BUTTON1())
if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
keys |= HAL_KEY_SW_6;
}
if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
{
keys |= HAL_KEY_SW_7;
}
as you can see, I change HAL_KEY_SW_6 , from HAL_PUSH_BUTTON1 to !.....
in HalKeyPoll
//if (HAL_PUSH_BUTTON1())
if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
keys |= HAL_KEY_SW_6;
}
if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
// if( (!(P1_6)))
{
keys |= HAL_KEY_SW_7;
}
nearly, I copied the process way as HAL_KEY_SW_6
in void halProcessKeyInterrupt (void)
if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) /* Interrupt Flag has been set */
{
HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); /* Clear Interrupt Flag */
valid = TRUE;
}
then add a interrupt
HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
{
if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
{
halProcessKeyInterrupt();
}
/*
Clear the CPU interrupt flag for Port_0
PxIFG has to be cleared before PxIF
*/
HAL_KEY_SW_7_PXIFG = 0;
HAL_KEY_CPU_PORT_1_IF = 0;
}
这俩个控件能上下交替的用动画实现切换, 最近发现很多应用都用页面内动画,控件间动画,不仅让应用档次大大的提高了,也使交互更优雅,更吸引用户。但是页面内动画怎么实现尼,也就是想让俩个控件setVisibility显示和消失,交替的动画。
这是俩个布局
mIvSearch = (ImageView) viewRoot.findViewById(R.id.iv_home_search); mIvChooseSType = (ImageView) viewRoot.findViewById(R.id.tv_chooseSType);
mIsShowSearchView = false;
/* * 点击搜索按钮,弹出搜索框 */
mIvSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mIsShowSearchView = true; Animation topOut = AnimationUtils.loadAnimation(getActivity(), R.anim.push_top_out); topOut.setAnimationListener(HomeFragment.this); Animation bottomIn = AnimationUtils.loadAnimation( getActivity(), R.anim.push_bottom_in); bottomIn.setAnimationListener(HomeFragment.this); mRyActionBar.startAnimation(topOut); mRySearch.startAnimation(bottomIn); } });
mIvCancle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // mRyActionBar.setVisibility(View.VISIBLE); // mRySearch.setVisibility(View.GONE); mIsShowSearchView = false; Animation topIn = AnimationUtils.loadAnimation(getActivity(), R.anim.push_top_in); topIn.setAnimationListener(HomeFragment.this); Animation bottomOut = AnimationUtils.loadAnimation( getActivity(), R.anim.push_bottom_out); topIn.setAnimationListener(HomeFragment.this); mRyActionBar.startAnimation(topIn); mRySearch.startAnimation(bottomOut); } });让Acitivty实现implements AnimationListener
@Override public void onAnimationEnd(Animation animation) { if (mIsShowSearchView) { mRyActionBar.setVisibility(View.GONE); } else { mRySearch.setVisibility(View.GONE); } } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { if (mIsShowSearchView) { mRySearch.setVisibility(View.VISIBLE); } else { mRyActionBar.setVisibility(View.VISIBLE); } }
开始的时候遇到一个问题,每次都是A布局消失后,B布局突然出现,而不是慢慢跟着A出现,后来公司大鸟提醒,两个布局是不能用LinearLayout包裹,因为用LinearLayout包裹的话,控件处于垂直布局或者水平布局,那么必须等一个布局消失了另一个才会出现,但是俩个同时的动画,A消失了,B的动画已经结束了,所以才会出现B突然出现,感觉没有执行动画的情况。换 成了FrameLayout就解决了
还有就是几个动画,都的很简单的移动动画
push_bottom_in.xml
push_bottom_out.xml
top_enter.xml
top_exit.xml
遇到如下问题:viewpager滑动时如果想跳过很多条直接到最后一条,中间会黑屏。黑屏是因为中间的view没有加载出来的缘故。
stackOverflow上看到的,在这里记录一下,
public class FixedScroller extends Scroller {
private int mDuration = 500;
public FixedScroller(Context context) {
super(context);
}
public FixedScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
// Ignore received duration, use fixed one instead
super.startScroll(startX, startY, dx, dy, mDuration);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy) {
// Ignore received duration, use fixed one instead
super.startScroll(startX, startY, dx, dy, mDuration);
}
}
然后再:
try {
Field mScroller;
mScroller = ViewPager.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);
Interpolator sInterpolator = new AccelerateDecelerateInterpolator();
FixedScroller scroller = new FixedScroller(viewPager.getContext(), sInterpolator);
mScroller.set(viewPager, scroller);
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
住要是设置了滑动的时间间隔和滑动时的拦截器。
这样滑动就能看到中间的确是有黑屏的。
最后再在加上:
@Override
public void onClick(View v) {
viewPager.setCurrentItem(3);
viewPager.setCurrentItem(c_current-1);
}
主要因为滑动时,加载3个view,所以给中间让他滑动到中间一次就可以解决这个问题。