如何优化用Java se 开发出来的图形界面

如题所述

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lingnet.app.tv.R;
import com.lingnet.app.tv.bean.BaseBean;
import com.lingnet.app.tv.bean.HomeBean;
import com.lingnet.app.tv.constant.RequestType;
import com.lingnet.app.tv.utill.ScaleAnimEffect;

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnFocusChange;
import retrofit2.Call;

/**
 */
public class TvHomeFragment extends BaseFragment {
    //    @BindView(R.id.tv_date)
//    TextView mTvDate;
//    @BindView(R.id.tv_xq)
//    TextView mTvXq;
//    @BindView(R.id.tv_time)
//    TextView mTvTime;
//
//    TimeChangeReceiver timeChangeReceiver;
    private ScaleAnimEffect animEffect;

    String liveUrl = "";

    public TvHomeFragment() {
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     */
    public static TvHomeFragment newInstance() {
        TvHomeFragment fragment = new TvHomeFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }
        this.animEffect = new ScaleAnimEffect();
    }

    @OnClick({R.id.layout_hswh, R.id.layout_fzcc, R.id.layout_szzy, R.id.layout_szbog, R.id.ll_memory
            , R.id.layout_qwyc, R.id.layout_qpx, R.id.layout_zxdt, R.id.layout_whdt})
    void onclick(View v) {
        switch (v.getId()) {
            case R.id.layout_hswh:
                startNextActivity(null, HushiCultureActivity.class);
                break;
            case R.id.layout_fzcc:
                startNextActivity(null, FeiyiListActivity.class);
                break;
            case R.id.layout_szzy:
                startNextActivity(null, DigitalResourceActivity.class);

                break;
            case R.id.layout_szbog:
                startNextActivity(null, DigitalMuseumListActivity.class);
                break;
            case R.id.ll_memory:
                startNextActivity(null, CitymemoryListActivity.class);
                break;
            case R.id.layout_qwyc:
                startNextActivity(null, QzycListActivity.class);

                break;
            case R.id.layout_qpx:
                startNextActivity(null, QzpxListActivity.class);

                break;
            case R.id.layout_zxdt:
                startNextActivity(null, InformationListActivity.class);
                break;

            case R.id.layout_whdt:
                if (TextUtils.isEmpty(liveUrl)) {
                    showToast("暂无直播内容");
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putString("url", liveUrl);
//                bundle.putString("url", "http://shangzhibo.tv/watch/4104455");
                    startNextActivity(bundle, ProgressWebviewActivity.class);
                }
                break;

        }
    }

    @OnFocusChange({R.id.layout_hswh, R.id.layout_fzcc, R.id.layout_szzy, R.id.layout_szbog, R.id.ll_memory
            , R.id.layout_qwyc, R.id.layout_qpx, R.id.layout_zxdt, R.id.layout_whdt})
    void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            onFocusView(v);
            return;
        }
        offFocusView(v);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_tv_home, container, false);
        ButterKnife.bind(this, v);
//        setTime();
//        //
//        IntentFilter intentFilter = new IntentFilter();
//        intentFilter.addAction(Intent.ACTION_TIME_TICK);//每分钟变化
//        intentFilter.addAction(Intent.ACTION_TIME_CHANGED);//设置了系统时间
//        timeChangeReceiver = new TimeChangeReceiver();
//        mActivity.registerReceiver(timeChangeReceiver, intentFilter);
        sendRequest();
        return v;
    }

    private void sendRequest() {
        Call<BaseBean> call = client.homepage();
        sendRequest(call, RequestType.homepage, true);
    }

    @Override
    public void requestCallBack(String dataJson, RequestType type) {
        switch (type) {
            case homepage:
                if (!TextUtils.isEmpty(dataJson)) {
                    HomeBean homeBean = mGson.fromJson(dataJson, HomeBean.class);
                    liveUrl = homeBean.getImage_link();
                } else {
                    showToast("接口返回数据格式错误");
                }
                break;
        }
    }

    @Override
    public void requestFailed(String error, RequestType type) {

    }

    private void onFocusView(View view) {
        view.bringToFront();
        this.animEffect.setAttributs(1.0F, 1.1F, 1.0F, 1.1F, 100L);
        view.startAnimation(this.animEffect.createAnimation());
    }

    private void offFocusView(View view) {
        this.animEffect.setAttributs(1.1F, 1.0F, 1.1F, 1.0F, 100L);
        view.startAnimation(this.animEffect.createAnimation());
    }

//    class TimeChangeReceiver extends BroadcastReceiver {
//        @Override
//        public void onReceive(Context context, Intent intent) {
//            switch (intent.getAction()) {
//                case Intent.ACTION_TIME_TICK:
//                    //每过一分钟 触发
//                    setTime();
//                    break;
//                case Intent.ACTION_TIME_CHANGED:
//                    //设置了系统时间
//                    setTime();
//                    break;
//            }
//        }
//    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
//        mActivity.unregisterReceiver(timeChangeReceiver);
    }

//    private void setTime() {
//        Calendar c = Calendar.getInstance();
//        int mMOth = c.get(Calendar.MONTH) + 1;
//        mTvDate.setText(mMOth + "-" + c.get(Calendar.DAY_OF_MONTH));
//        // 取得系统时间:
//        int hour = c.get(Calendar.HOUR_OF_DAY);
//        int minute = c.get(Calendar.MINUTE);
//        mTvTime.setText(hour + ":" + minute);
//        int week = c.get(Calendar.DAY_OF_WEEK);
//        String[] weeks = new String[]{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
//        mTvXq.setText(weeks[week - 1]);
//    }
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-08-02
可以了解一下PLAF ,如果你真的是想用Java开发桌面应用!