public abstract class BaseActivity extends AppCompatActivity implements InitUI, View.OnClickListener{

    /**屏幕的宽度*/
    protected int mScreenWidth;
    /**屏幕高度*/
    protected int mScreenHeight;
    /**屏幕密度*/
    protected float mDensity;

    private Toast mToast;

    public int getmScreenWidth() {
        return mScreenWidth;
    }

    public void setmScreenWidth(int mScreenWidth) {
        this.mScreenWidth = mScreenWidth;
    }

    public int getmScreenHeight() {
        return mScreenHeight;
    }

    public void setmScreenHeight(int mScreenHeight) {
        this.mScreenHeight = mScreenHeight;
    }

    public float getmDensity() {
        return mDensity;
    }

    public void setmDensity(float mDensity) {
        this.mDensity = mDensity;
    }

    private WindowManager mWindowManager = null;
    private View mNightView = null;
    private WindowManager.LayoutParams mNightViewParam;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTheme();
        setContentView(getLayoutId());
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        setmScreenWidth(metric.widthPixels);
        setmScreenHeight(metric.heightPixels);
        mDensity = metric.density;
        initData();
        initView();
        initEvent();
        mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

    }

    /**
     * 这里得到Layout的id
     * @return layout布局的id
     */
    public abstract int getLayoutId();

    protected void startActivity(Class<?> cls) {
        Intent intent = new Intent();
        intent.setClass(this, cls);
        startActivity(intent);
    }

    protected void startActivity(Class<?> cls, Bundle bundle) {
        Intent intent = new Intent();
        intent.putExtras(bundle);
        intent.setClass(this, cls);
        startActivity(intent);
    }


    public void showToast(String text) {
        if (mToast != null) {
            mToast.cancel();
        }
        mToast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
        mToast.show();

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

    protected void initNightView(int layoutID) {
        mNightViewParam = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_APPLICATION,
                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSPARENT);
        if (mNightView == null) {
            mNightView = LayoutInflater.from(this).inflate(layoutID, null);
            mWindowManager.addView(mNightView, mNightViewParam);
        }
    }

    protected void removeNightView(){
        if(mNightView!=null) {
            mWindowManager.removeViewImmediate(mNightView);
            mNightView = null;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
} public class AboutFragment extends BaseFragment {
    public static final String TAG = "com.weather.byhieg.easyweather.slidemenu.about.AboutFragment";


    public AboutFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        getActivity().setTheme(R.style.DayTheme);
        if (MyApplication.nightMode2()) {
            initNightView(R.layout.night_mode_overlay);
        }

        View view = inflater.inflate(R.layout.fragment_about, container, false);
        TextView tv = (TextView) view.findViewById(R.id.link);
        String textStr = "https://github.com/byhieg/easyweather";
        tv.setAutoLinkMask(Linkify.WEB_URLS);
        tv.setText(textStr);
        Spannable s = (Spannable) tv.getText();
        s.setSpan(new UnderlineSpan() {
            @Override
            public void updateDrawState(TextPaint ds) {
                ds.setColor(ds.linkColor);
                ds.setUnderlineText(false);
            }
        }, 0, textStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return view;
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

    }
} public class FutureFragment extends BaseFragment implements FutureContract.View {

    public static final String TAG = "com.weather.byhieg.easyweather.slidemenu.future.FutureFragment";
    private ArrayList<FutureContext> lists = new ArrayList<>();
    private FutureListAdapter adapter;
    private FutureContract.Presenter mPresenter;

    @BindView(R.id.future_recycler_view)
    public RecyclerView recyclerView;

    public FutureFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        getActivity().setTheme(R.style.DayTheme);
        if (MyApplication.nightMode2()) {
            initNightView(R.layout.night_mode_overlay);
        }
        View view = inflater.inflate(R.layout.fragment_future, container, false);
        ButterKnife.bind(this, view);
        mPresenter.start();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void setPresenter(FutureContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public void showListView(List<FutureContext> list) {
        adapter = new FutureListAdapter(list);
        Logger.d(list.get(0).getCond());
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

    }
} public class FuturePresenter implements FutureContract.Presenter {


    private WeatherRepository mWeatherRepository;
    private FutureContract.View mView;


    public FuturePresenter(FutureContract.View view) {
        mView = view;
        mWeatherRepository = WeatherRepository.getInstance();
        mView.setPresenter(this);
    }


    @Override
    public void start() {
        loadData();
    }

    @Override
    public void loadData() {
        List<FutureContext> lists = new ArrayList<>();
        HWeather weather = mWeatherRepository.getLocalWeather(mWeatherRepository.getShowCity());
        String[] weeks = new String[0];
        try {
            weeks = DateUtil.
                    getNextWeek(new SimpleDateFormat("yyyy-MM-dd").
                            parse(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(0).getDate()));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        for(int i = 0; i < WeatherJsonConverter.getWeather(weather).getDaily_forecast().size(); i++) {
            FutureContext fc = new FutureContext();
            fc.setCond(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getCond().getTxt_d());
            fc.setHum(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getHum());
            fc.setTmp(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getTmp().getMax() + "°" + "/" +
                    WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getTmp().getMin() + "°");

            fc.setWind(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getWind().getSpd());
            fc.setVis(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getVis());
            fc.setPop(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getPop());
            fc.setSunrise(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getAstro().getSr());
            fc.setSunset(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getAstro().getSs());
            fc.setPcpn(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getPcpn());
            fc.setPres(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getPres());
            fc.setDes(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getWind().getDir());
            fc.setTime(weeks[i]);
            lists.add(fc);
        }
        mView.showListView(lists);
    }
} public class HelpFragment extends BaseFragment {

    public static final String TAG = "com.weather.byhieg.easyweather.slidemenu.help.HelpFragment";

    public HelpFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        getActivity().setTheme(R.style.DayTheme);
        if (MyApplication.nightMode2()) {
            initNightView(R.layout.night_mode_overlay);
        }
        return inflater.inflate(R.layout.fragment_help, container, false);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

    }
} public class LaboratoryFragment extends BaseFragment {

    public static final String TAG = "com.weather.byhieg.easyweather.slidemenu.lab.LaboratoryFragment";

    private CardView cardView;
    private TextView textView;

    private Switch aSwitch;
    private View view;

//    private WindowManager mWindowManager = null;
//    private View mNightView = null;
//    private LayoutParams mNightViewParam;

    public LaboratoryFragment() {
    }

    public static LaboratoryFragment getInstance() {
        LaboratoryFragment fragment = new LaboratoryFragment();
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getActivity().setTheme(R.style.DayTheme);
        if (MyApplication.nightMode2()) {
            initNightView(R.layout.night_mode_overlay);
        }

        view = inflater.inflate(R.layout.fragment_laboratory, null);
        initView();
        return view;
    }

    public void initView() {
        cardView = (CardView) view.findViewById(R.id.item1);
        textView = (TextView) view.findViewById(R.id.lab_textview);
        textView.setText(R.string.nightMode1);
        aSwitch = (Switch) cardView.findViewById(R.id.cb);
        SharedPreferences sharedPreferences = getActivity().getSharedPreferences(MyApplication.shareFilename2, getActivity().MODE_PRIVATE);
        boolean checked = sharedPreferences.getBoolean("ischecked", false);
        aSwitch.setChecked(checked);
        switchStatus(aSwitch, MyApplication.shareFilename2);


    }

    public void switchStatus(Switch aSwitch, final String fileName) {
        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences settings = getActivity().getSharedPreferences(fileName, Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = settings.edit();
                edit.putBoolean("ischecked", isChecked);
                edit.commit();

                if (isChecked) {
                    initNightView(R.layout.night_mode_overlay);
                } else {
                    removeNightView();
                }
            }

        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
} public class SettingFragment extends BaseFragment {

    public static final String TAG = "com.weather.byhieg.easyweather.slidemenu.setting.SettingFragment";


    public SettingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        getActivity().setTheme(R.style.DayTheme);
        if (MyApplication.nightMode2()) {
            initNightView(R.layout.night_mode_overlay);
        }
        View view = inflater.inflate(R.layout.fragment_setting, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        Switch logSwitch = (Switch) view.findViewById(R.id.log_switch);
        SharedPreferences log = getActivity().getSharedPreferences(MyApplication.logFilename, getActivity().MODE_PRIVATE);
        boolean logChecked = log.getBoolean("ischecked", true);
        logSwitch.setChecked(logChecked);
        switchStatus(logSwitch, MyApplication.logFilename,1);


        Switch notificationSwitch = (Switch) view.findViewById(R.id.notification_switch);
        SharedPreferences notification = getActivity().getSharedPreferences(MyApplication.notificationname, getActivity().MODE_PRIVATE);
        boolean notificationChecked = notification.getBoolean("ischecked", true);
        notificationSwitch.setChecked(notificationChecked);
        switchStatus(notificationSwitch, MyApplication.notificationname,2);

        Switch widgetSwitch = (Switch) view.findViewById(R.id.widget_switch);
        SharedPreferences widget = getActivity().getSharedPreferences(MyApplication.widgetname, getActivity().MODE_PRIVATE);
        boolean widgetChecked = widget.getBoolean("ischecked", true);
        widgetSwitch.setChecked(widgetChecked);
        switchStatus(widgetSwitch, MyApplication.widgetname,3);

        Switch cacheSwitch = (Switch) view.findViewById(R.id.cache_switch);
        SharedPreferences cache = getActivity().getSharedPreferences(MyApplication.cachename, getActivity().MODE_PRIVATE);
        boolean cacheChecked = cache.getBoolean("ischecked", true);
        cacheSwitch.setChecked(cacheChecked);
        switchStatus(cacheSwitch,MyApplication.cachename,4);
    }

    public void switchStatus(Switch aSwitch, final String fileName, final int flag) {
        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences settings = getActivity().getSharedPreferences(fileName, Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = settings.edit();
                edit.putBoolean("ischecked", isChecked);
                edit.apply();
                if (isChecked) {
                    if (flag == 2) {
                        getActivity().startService(new Intent(getActivity(), NotificationService.class));
                    }
                }else{
                    if (flag == 2) {
                        getActivity().stopService(new Intent(getActivity(), NotificationService.class));
                    }
                }
            }

        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
} public class ShareFragment extends BaseFragment {
    public static final String TAG = "com.weather.byhieg.easyweather.slidemenu.share.ShareFragment";
    private File[] files = new File[3];

    public ShareFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        getActivity().setTheme(R.style.DayTheme);
        if (MyApplication.nightMode2()) {
            initNightView(R.layout.night_mode_overlay);
        }
        View view = inflater.inflate(R.layout.fragment_share, container, false);
        files[0] = new File(MyApplication.getAppContext().getExternalFilesDir(null),
                "IMG-BRIEF"  + ".png");
        files[1] = new File(MyApplication.getAppContext().getExternalFilesDir(null),
                "IMG-DETAIL" + ".png");
        files[2] = new File(MyApplication.getAppContext().getExternalFilesDir(null),
                "IMG-FUTURE"  + ".png");
        initView(view);
        return view;
    }

    private void initView(View view){
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView_brief);
        imageView.setImageURI(Uri.fromFile(files[0]));

        ImageView imageDetail = (ImageView) view.findViewById(R.id.imageView_detail);
        imageDetail.setImageURI(Uri.fromFile(files[1]));

        ImageView imageFuture = (ImageView) view.findViewById(R.id.imageView_future);
        imageFuture.setImageURI(Uri.fromFile(files[2]));

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareContent shareContent = new ShareContent();
                startActivity(Intent.createChooser(
                        shareContent.startShare(
                                getActivity().getClass().getSimpleName(),
                                files[0]),"分享天气"));
            }
        });

        imageDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareContent shareContent = new ShareContent();
                startActivity(Intent.createChooser(
                        shareContent.startShare(
                                getActivity().getClass().getSimpleName(),
                                files[1]),"分享天气"));
            }
        });

        imageFuture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareContent shareContent = new ShareContent();
                startActivity(Intent.createChooser(
                        shareContent.startShare(
                                getActivity().getClass().getSimpleName(),
                                files[2]),"分享天气"));
            }
        });

    }



    @Override
    public void onDestroy() {
        super.onDestroy();
    }
} public class WikiFragment extends BaseFragment {

    public static final String TAG = "com.weather.byhieg.easyweather.slidemenu.wiki.WikiFragment";
    private String[] tags;
    private String[] links;

    public WikiFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        getActivity().setTheme(R.style.DayTheme);
        if (MyApplication.nightMode2()) {
            initNightView(R.layout.night_mode_overlay);
        }
        View view = inflater.inflate(R.layout.fragment_wiki, container, false);
        initData();
        initView(view);
        return view;
    }


    private void initView(View view) {
        final LayoutInflater mInflater = LayoutInflater.from(getActivity());
        final TagFlowLayout flowLayout = (TagFlowLayout) view.findViewById(R.id.id_flowlayout);
        flowLayout.setAdapter(new TagAdapter<String>(tags) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) mInflater.inflate(R.layout.item_flow_layout,
                        flowLayout, false);
                tv.setText(s);
                return tv;
            }
        });

        flowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent){
                Intent intent = new Intent(getActivity(), WikiResultActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("keyWord",tags[position]);
                bundle.putString("url",links[position]);
                intent.putExtra("result", bundle);
                startActivity(intent);
                return true;
            }
        });
    }

    private void initData() {
        tags = new String[]{
                "晴", "风", "雨", "雷阵雨", "台风", "冰雹", "云", "湿度", "降雨量",
                "紫外线", "能见度", "PM2.5", "PM10", "雪", "摄氏度", "华氏度"};

        links = new String[]{
                "http://baike.baidu.com/subview/42733/8097631.htm#viewPageContent",
                "http://baike.baidu.com/subview/17988/7589816.htm#viewPageContent",
                "http://baike.baidu.com/subview/27432/6630580.htm#viewPageContent",
                "http://baike.baidu.com/item/%E9%9B%B7%E9%98%B5%E9%9B%A8/7602073",
                "http://baike.baidu.com/item/%E5%8F%B0%E9%A3%8E/17003",
                "http://baike.baidu.com/item/%E5%86%B0%E9%9B%B9/2072195",
                "http://baike.baidu.com/subview/24937/9154496.htm#viewPageContent",
                "http://baike.baidu.com/view/286584.htm",
                "http://baike.baidu.com/view/1745.htm",
                "http://baike.baidu.com/subview/598/14136534.htm#viewPageContent",
                "http://baike.baidu.com/view/419927.htm",
                "http://baike.baidu.com/view/4251816.htm?fromtitle=PM2.5&fromid=353332&type=syn",
                "http://baike.baidu.com/view/489133.htm?fromtitle=PM10&fromid=4066123&type=syn",
                "http://baike.baidu.com/item/%E9%9B%AA/2886691",
                "http://baike.baidu.com/view/423347.htm",
                "http://baike.baidu.com/view/562306.htm"};
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
} public class Constants implements Serializable{


    public static final int FUTURE = 0x0;
    public static final int SETTING = 0x1;
    public static final int SHARE = 0x2;
    public static final int HELP = 0x3;
    public static final int LAB = 0x4;
    public static final int WIKI = 0x5;
    public static final int ABOUT = 0x6;


    //权限的标识
    public static final int PERMISSION = 0x201;


    public static final int NOTIFICATION_ID = 0X301;


    public static final int UPDATE_WEATHER = 0X401;

    public static final int UPDATE_SHOW_CITY = 0x402;






}
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import com.weather.byhieg.easyweather.base.BaseActivity;
import com.weather.byhieg.easyweather.R;
import com.weather.byhieg.easyweather.slidemenu.about.AboutFragment;
import com.weather.byhieg.easyweather.slidemenu.future.FutureFragment;
import com.weather.byhieg.easyweather.slidemenu.future.FuturePresenter;
import com.weather.byhieg.easyweather.slidemenu.help.HelpFragment;
import com.weather.byhieg.easyweather.slidemenu.lab.LaboratoryFragment;
import com.weather.byhieg.easyweather.slidemenu.setting.SettingFragment;
import com.weather.byhieg.easyweather.slidemenu.share.ShareFragment;
import com.weather.byhieg.easyweather.slidemenu.wiki.WikiFragment;
import com.weather.byhieg.easyweather.tools.Constants;
import butterknife.BindView;
import butterknife.ButterKnife;
package com.weather.byhieg.easyweather.slidemenu;



public class SlideMenuActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    public Toolbar toolbar;

    private FragmentManager fm;
    public FuturePresenter mPresenter;


    @Override
    public int getLayoutId() {
        return R.layout.activity_laboratory;
    }

    @Override
    public void initData() {
        ButterKnife.bind(this);

        fm = getSupportFragmentManager();
    }
    @Override
    public void initView() {

        int position = getIntent().getIntExtra("itemId", 0);
        switch (position){
            case Constants.FUTURE:
                toolbar.setTitle(R.string.future);
                FutureFragment futureFragment = new FutureFragment();
                fm.beginTransaction()
                        .add(R.id.fragment, futureFragment,FutureFragment.TAG).commit();
                mPresenter = new FuturePresenter(futureFragment);
                break;
            case Constants.SETTING:
                toolbar.setTitle(R.string.setting);
                Fragment fragment = new SettingFragment();