android.permission.BLUETOOTH 权限
MediaButtonIntentReceiver mMediaButtonReceiver = new MediaButtonIntentReceiver();
IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
mediaFilter.setPriority(MEDIA_BUTTON_INTENT_EMPIRICAL_PRIORITY_VALUE);
registerReceiver(mMediaButtonReceiver, mediaFilter);
不要忘记设置优先权
public class HardButtonReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.v(“TestApp”, “Button press received”);
abortBroadcast();
KeyEvent key = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if(key.getAction() == KeyEvent.ACTION_UP)
{
int keycode = key.getKeyCode();
if(keycode == KeyEvent.KEYCODE_MEDIA_NEXT)
{
Log.d(“TestApp”, “Next Pressed”);
}
else if(keycode == KeyEvent.KEYCODE_MEDIA_PREVIOUS)
{
Log.d(“TestApp”, “Previous pressed”);
}
else if(keycode == KeyEvent.KEYCODE_HEADSETHOOK)
{
Log.d(“TestApp”, “Head Set Hook pressed”);
}
}
}
}
因为有些按键不一定被映射却要检查
#pragma mark iAd - (void)addIAdBanner { // if place the banner on the bottom // adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; adView = [[ADBannerView alloc] initWithFrame:CGRectMake(320 - (32 / 2) - 480 / 2, 480 / 2 - (50 - (32 / 2)), 0, 0)]; adView.frame = CGRectOffset(adView.frame, 32, 0); // hide adView.delegate = self; adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]; adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32; [[[CCDirector sharedDirector] openGLView] addSubview:adView]; // Transform iAd adView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90)); iAdBannerIsVisible = NO; } - (void)removeIAdBanner { // clear iAd adView.delegate = nil; [adView removeFromSuperview]; [adView release]; adView = nil; iAdBannerIsVisible = NO; } - (void)bannerViewDidLoadAd:(ADBannerView *)banner { NSLog(@"[iAd]: Ad did load."); if (!iAdBannerIsVisible) { adView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0)); adView.frame = CGRectOffset(adView.frame, -32, 0); adView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90)); iAdBannerIsVisible = YES; } if (admobBannerIsVisible) { // hide it adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0)); adMobAd.frame = CGRectMake(140 + 48, 215, 320, 48); adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90)); } } - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { NSLog(@"[iAd]: Faild to load the banner: %@", error); if (iAdBannerIsVisible) { adView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0)); adView.frame = CGRectOffset(adView.frame, 32, 0); adView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90)); iAdBannerIsVisible = NO; } if (admobBannerIsVisible) { // show it adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0)); adMobAd.frame = CGRectMake(140, 215, 320, 48); adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90)); } } - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave { NSLog(@"[iAd]: An action was started from the banner. Application will quit: %d", willLeave); return YES; } - (void)bannerViewActionDidFinish:(ADBannerView *)banner { NSLog(@"[iAd]: Action finished."); } #pragma mark AdMobDelegate methods - (NSString *)publisherIdForAd:(AdMobView *)adView { return @"a14c561cd7cbb82"; // this should be prefilled; if not, get it from www.admob.com } - (UIViewController *)currentViewControllerForAd:(AdMobView *)adView { return controller; } - (UIColor *)adBackgroundColorForAd:(AdMobView *)adView { return [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; // this should be prefilled; if not, provide a UIColor } - (UIColor *)primaryTextColorForAd:(AdMobView *)adView { return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor } - (UIColor *)secondaryTextColorForAd:(AdMobView *)adView { return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor } // Sent when an ad request loaded an ad; this is a good opportunity to attach // the ad view to the hierachy. - (void)didReceiveAd:(AdMobView *)adView { NSLog(@"AdMob: Did receive ad"); adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0)); adMobAd.frame = CGRectMake(140, 215, 320, 48); adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90)); if (iAdBannerIsVisible) { // if iAdBannerIsVisible, hide admob banner adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0)); adMobAd.frame = CGRectMake(140 + 48, 215, 320, 48); adMobAd.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90)); } [[[CCDirector sharedDirector] openGLView] addSubview:adMobAd]; [refreshTimer invalidate]; refreshTimer = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES]; admobBannerIsVisible = YES; } // Sent when an ad request failed to load an ad - (void)didFailToReceiveAd:(AdMobView *)adView { NSLog(@"field receive admob."); [adMobAd removeFromSuperview]; [self performSelector:@selector(requestAd) withObject:nil afterDelay:2.0]; admobBannerIsVisible = NO; } - (void)refreshAd:(ccTime)dt { NSLog(@"refresh admob."); [adMobAd requestFreshAd]; } - (void)requestAd { adMobAd = [AdMobView requestAdWithDelegate:self]; }
今天做东西时感觉使用一下抖动效果好看一下,当然有时候不明显,如果你需要看明显的效果的话 就应该方法图片来看
<?xml version="1.0" encoding="UTF-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="/blog_article/@drawable/b1/index.html" android:dither="true" />
<?xml version="1.0" encoding="UTF-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="/blog_article/@drawable/b1/index.html" android:tileMode="repeat" android:dither="true" />
findViewById(R.id.ImageView01).getBackground().setDither(true);
如果要引用上面的可以设置 drawable来实现,
但是抖动不能直接应用在dialog中,因为里面的背景通常是透明 transparent 的,
可以间接使用getWindow().setFlags(WindowManager.LayoutParams.FLAG_DITHER, WindowManager.LayoutParam