Skip to content

Instantly share code, notes, and snippets.

View tuchangwei's full-sized avatar

Changwei tuchangwei

View GitHub Profile
package ws.otero.adrian.gridexample;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
// First create the GestureListener that will include all our callbacks.
// Then create the GestureDetector, which takes that listener as an argument.
GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener();
final GestureDetector gd = new GestureDetector(getActivity(), gestureListener);
/* For the view where gestures will occur, create an onTouchListener that sends
* all motion events to the gesture detector. When the gesture detector
* actually detects an event, it will use the callbacks you created in the
* SimpleOnGestureListener to alert your application.
*/
<!--抽屉效果, 有两部分组成,上边部分是主view, 下边部分是抽屉部分,抽屉部分的抽出方向由android:layout_gravity="start"这个参数决定-->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
//app为自定义namespace的名称
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 主view由相对布局构成-->
<RelativeLayout
显示文档: Ctr+J
查找调用位置:Ctrl + Option + H
- (void)customAppearance {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
//[[UINavigationBar appearance]setBackgroundColor:[UIColor colorWithRed:26.0/255 green:26.0/255 blue:129.0/255 alpha:1.0]];
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"navbar_bg"]forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
[[UINavigationBar appearance]setTranslucent:NO];
//RGB color macro
#define NormalBlue 0x25aae1
#define PressedBlue 0x1A7AA2
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//RGB color macro with alpha
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
+ (NSString *) appVersion
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
}
+ (NSString *) build
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
#else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTy
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)