com.louding.frame.ui.FrameActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.louding.frame.ui.FrameActivity.java

Source

/*
 * Copyright (c) 2014,KJFrameForAndroid Open Source Project,.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.louding.frame.ui;

import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;

/**
 * Activity's framework,the developer shouldn't extends it<br>
 * 
 * <b></b> 2014-3-1 <br>
 * <b>?</b> 2014-10-17<br>
 * 
 * @author kymjs(kymjs123@gmail.com)
 * @version 1.8
 */
public abstract class FrameActivity extends FragmentActivity
        implements OnClickListener, I_BroadcastReg, I_KJActivity, I_SkipActivity {

    public static final int WHICH_MSG = 0X37210;

    /**
     * ?????
     */
    private interface ThreadDataCallBack {
        void onSuccess();
    }

    private static ThreadDataCallBack callback;

    // ?????
    private static Handler threadHandle = new Handler() {
        @Override
        public void handleMessage(android.os.Message msg) {
            if (msg.what == WHICH_MSG) {
                callback.onSuccess();
            }
        };
    };

    /**
     * initDataFromThread()????
     */
    protected void threadDataInited() {
    }

    /**
     * ????UI?
     */
    @Override
    public void initDataFromThread() {
        callback = new ThreadDataCallBack() {
            @Override
            public void onSuccess() {
                threadDataInited();
            }
        };
    }

    @Override
    public void initData() {
    }

    @Override
    public void initWidget() {
    }

    // ??
    private void initializer() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                initDataFromThread();
                threadHandle.sendEmptyMessage(WHICH_MSG);
            }
        }).start();
        initData();
        initWidget();
    }

    /** listened widget's click method */
    @Override
    public void widgetClick(View v) {
    }

    @Override
    public void onClick(View v) {
        widgetClick(v);
    }

    @Override
    public void registerBroadcast() {
    }

    @Override
    public void unRegisterBroadcast() {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRootView(); // annotate?
        AnnotateUtil.initBindView(this);
        initializer();
        registerBroadcast();
    }

    @Override
    protected void onDestroy() {
        unRegisterBroadcast();
        super.onDestroy();
    }

    /**
     * Fragment?
     * 
     * @param resView
     *            ??
     * @param targetFragment
     *            ??Fragment
     */
    public void changeFragment(int resView, KJFragment targetFragment) {
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(resView, targetFragment, targetFragment.getClass().getName());
        transaction.commit();
    }
}