Java DOM 解析 GBK 编码的 XML

final String XMLString = ""
                    + ""
                    + "张三"
                    + "";

private static final DocumentBuilderFactory sDocBuilderFactory = 	     					  DocumentBuilderFactory.newInstance();
DocumentBuilder builder = sDocBuilderFactory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(xmlString.getBytes("GBK"));
Reader reader = new InputStreamReader(is, "GBK");
InputSource source = new InputSource(reader);
Document doc = builder.parse(source);

Mac Eclipse 中文乱码

MacEclipse中文乱码

iOS PickerView 联动

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"provinces_cities" ofType:@"plist"];
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    self.pickerData = dict;
    self.pickerProvincesData = [self.pickerData allKeys];
    
    NSString *selectedProvincesData = [self.pickerProvincesData objectAtIndex:0];
    self.pickerCitiesData = [self.pickerData objectForKey:selectedProvincesData];
    
    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;
}

- (NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if (component == 0) {
        return [self.pickerProvincesData objectAtIndex:row];
    } else {
        return [self.pickerCitiesData objectAtIndex:row];
    }
}

- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == 0) {
        NSString *selectedProvince = [self.pickerProvincesData objectAtIndex:row];
        NSArray *array = [self.pickerData objectForKey:selectedProvince];
        self.pickerCitiesData = array;
        [self.pickerView reloadComponent:1];
    }
}


- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 2;
}

- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    
    if (component == 0) {
        return [self.pickerProvincesData count];
    } else {
        return [self.pickerCitiesData count];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onClick:(UIButton *)sender {
    NSInteger row1 = [self.pickerView selectedRowInComponent:0];
    NSInteger row2 = [self.pickerView selectedRowInComponent:1];
    NSString *selected1 = [self.pickerProvincesData objectAtIndex:row1];
    NSString *selected2 = [self.pickerCitiesData objectAtIndex:row2];
    NSString *title = [[NSString alloc] initWithFormat:@"%@, %@市", selected1, selected2];
    self.label.text = title;
}
@end

Android 获取 View 显示区域截图

 private Bitmap mCopyBmp = null;
   
 private Bitmap captureVisibleBitmap(View view) {
        view.setDrawingCacheEnabled(true);
        Bitmap copy = view.getDrawingCache();
        if (null != copy) {
            if (null != mCopyBmp) {
                mCopyBmp.recycle();
            }
            mCopyBmp = Bitmap.createBitmap(copy);
        }

        view.setDrawingCacheEnabled(false);
        return mCopyBmp;
    }

说明

  1. 不要试图在 onDraw() 方法中调用 getDrawingCache(), 因为 getDrawingCache() 内部会调用 onDraw()

  2. 如果不调用setDrawingCacheEnabled(true) 那么每次 getDrawingCache() 都需要调用 buildDrawingCache(), 重要的是在要记得最后调用 destroyDrawingCache()来释放 cache

  3. 在setDrawingCacheEnabled(true)的情况下,不需要调用 buildDrawingCache(),也不需要 destroyDrawingCache(), 系统会自动管理

OpenGL 顶点变换管线

opengl顶点变换管线

ref: 《OpenGL超级宝典 v4》