content: package cn.like.sample;
  
  import android.content.Intent;
  import android.graphics.drawable.Drawable;
  import android.os.Bundle;
  import android.support.annotation.DrawableRes;
  import android.support.graphics.drawable.VectorDrawableCompat;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import cn.like.nightmodel.ModelChangeListener;
  import cn.like.nightmodel.NightModelManager;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          NightModelManager.getInstance().attach(this);
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          Button button = (Button) findViewById(R.id.button);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  changeNightModel();
              }
          });
          Button open = (Button) findViewById(R.id.open);
          open.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  startActivity(new Intent(MainActivity.this, Main2Activity.class));
              }
          });
  
          ListView listView = (ListView) findViewById(R.id.list_view);
          listView.setAdapter(new SimpleAdapter());
  
          NightModelManager.getInstance().addModelChangeListener(new ModelChangeListener() {
              @Override
              public void onChanged(boolean isNight) {
                  Toast.makeText(getApplicationContext(), isNight?"night":"day", Toast.LENGTH_SHORT).show();
              }
          });
      }
  
      private void changeNightModel() {
          if (NightModelManager.getInstance().isCurrentNightModel(this)) {
              NightModelManager.getInstance().applyDayModel(this);
          } else {
              NightModelManager.getInstance().applyNightModel(this);
          }
      }
  
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      protected void onDestroy() {
          NightModelManager.getInstance().detach(this);
          super.onDestroy();
      }
  
      private static class SimpleAdapter extends BaseAdapter {
          private List<String> list = new ArrayList<>();
  
          public SimpleAdapter() {
              for (int i=0;i<50;i++) {
                  list.add("鹅鹅鹅");
                  list.add("曲项向天歌");
                  list.add("白毛浮绿水");
                  list.add("红掌拨清波");
              }
          }
  
          @Override
          public int getCount() {
              return list.size();
          }
  
          @Override
          public String getItem(int position) {
              return list.get(position);
          }
  
          @Override
          public long getItemId(int position) {
              return position;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              if (convertView == null) {
                  convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent, false);
              }
              ((TextView)convertView).setText(getItem(position));
              return convertView;
          }
      }
  }
  