Android 使用 StaticLayout 实现字符串换行

static class LongTextView extends View {
        private static final float TEXT_SIZE = 60;

        private static final CharSequence TEXT = "This is a long long long " +
                "long long long long long long long long long long " +
                "long long long string";

        TextPaint textPaint;

        public LongTextView(Context context) {
            super(context);
            textPaint = new TextPaint();
            textPaint.setColor(Color.BLUE);
            textPaint.setStyle(Paint.Style.FILL);
            textPaint.setTextSize(TEXT_SIZE);
        }

        public void onDraw(Canvas canvas) {
            super.onDraw(canvas);

            StaticLayout staticLayout = new StaticLayout(
                    TEXT, textPaint,
                    canvas.getWidth(),
                    Layout.Alignment.ALIGN_NORMAL,
                    1.0f, 0.0f, false
            );

            staticLayout.draw(canvas);
        }
    }

Android Studio 鼠标暂停显示帮助文档

Alt none

Android Create Floating Window

private void initFloatingWindow() {
        mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
        mWindow = PolicyManager.makeNewWindow(mContext);
        mWindow.setWindowManager(mWindowManager, null, null);
        mWindow.requestFeature(Window.FEATURE_NO_TITLE);
        mDecor = mWindow.getDecorView();
        mDecor.setOnTouchListener(mTouchListener);
        mWindow.setContentView(this);
        mWindow.setBackgroundDrawableResource(android.R.color.transparent);
        
        // While the media controller is up, the volume control keys should
        // affect the media stream type
        mWindow.setVolumeControlStream(AudioManager.STREAM_MUSIC);

        setFocusable(true);
        setFocusableInTouchMode(true);
        setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        requestFocus();
}

ref: MediaController.java

Xcode 使用 HTTP

XCode 7.0.1

ERROR:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

You can find this Note at Here.

App Transport Security

App Transport Security (ATS) enforces best practices in the secure connections between an app and its back end. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt; it is also on by default in iOS 9 and OS X v10.11. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one.

If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible. In addition, your communication through higher-level APIs needs to be encrypted using TLS version 1.2 with forward secrecy. If you try to make a connection that doesn't follow this requirement, an error is thrown. If your app needs to make a request to an insecure domain, you have to specify this domain in your app's Info.plist file.

Temporary Solution Alt none

iOS Create Thumbnail by means of offscreen image context

- (void)setThumbnailFromImage:(UIImage *)image {
    CGSize origImageSize = image.size;
    CGRect newRect = CGRectMake(0, 0, 40, 40);
    float ratio = MAX(newRect.size.width / origImageSize.width, newRect.size.height / origImageSize.height);

    UIGraphicsBeginImageContextWithOptions(newRect.size, NO, ratio);

    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:5.0];
    [path addClip];
    CGRect thumbRect;
    thumbRect.size.width = ratio * origImageSize.width;
    thumbRect.size.height = ratio * origImageSize.height;
    thumbRect.origin.x = (newRect.size.width - thumbRect.size.width) / 2.0;
    thumbRect.origin.y = (newRect.size.height - thumbRect.size.height) / 2.0;
    [image drawInRect:thumbRect];
    UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();

    //Get the thumbnail
    //self.thumbnail = thumbnail;
    
    UIGraphicsEndImageContext();
}