Example #1
0
 private void register(final String username, final String password) {
   AVUser user = new AVUser();
   user.setUsername(username);
   user.setPassword(password);
   user.signUpInBackground(
       new SignUpCallback() {
         @Override
         public void done(AVException e) {
           LogUtil.i(TAG, "register----" + e.getMessage());
           if (e == null) {
             login(username, password);
           } else {
             showToast(e.getMessage());
           }
         }
       });
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    UmengUpdateAgent.update(this);

    AVUser user = new AVUser();
    user.setUsername(SAFApp.getInstance().deviceid);
    user.setPassword("default");
    user.signUpInBackground(
        new SignUpCallback() {
          public void done(AVException e) {
            if (e == null) {
              // successfully
              // Log.d("mytag","success");
            } else {
              // Log.d("mytag","fail");
            }
          }
        });

    // 各种findviews
    toolbar = (Toolbar) findViewById(R.id.tl_custom);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.mainDrawer);
    lvLeftMenu = (ListView) findViewById(R.id.lv_left_menu);

    // 初始化左侧抽屉列表
    ArrayList<MyListViewItem> listViewItems = new ArrayList<>();
    listViewItems.add(new MyListViewItem("home", "首页", "\uF015"));
    listViewItems.add(new MyListViewItem("summary", "行情概览", "\uF201"));
    listViewItems.add(new MyListViewItem("block", "板块行情", "\uF00b"));
    listViewItems.add(new MyListViewItem("mine", "自选股", "\uF21e"));
    listViewItems.add(new MyListViewItem("moni", "模拟炒股", "\uF157"));
    listViewItems.add(new MyListViewItem("about", "关于", "\uF05a"));
    listViewItems.add(new MyListViewItem("exit", "退出应用", "\uF18e"));
    adapterForDrawerListview = new adapterForDrawerListview();
    adapterForDrawerListview.setData(listViewItems);
    lvLeftMenu.setAdapter(adapterForDrawerListview);
    lvLeftMenu.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mDrawerLayout.closeDrawers();
            jumpToFragment(position);
          }
        });

    FragmentMain fragmentMain = new FragmentMain();
    this.getSupportFragmentManager()
        .beginTransaction()
        .add(R.id.fragmentContainer, fragmentMain)
        .commit();

    toolbar.setTitle("模拟炒股CC");
    toolbar.setTitleTextColor(Color.parseColor("#ffffff")); // 设置标题颜色
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true); // 设置返回键可用
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // 创建返回键,并实现打开关/闭监听
    mDrawerToggle =
        new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.open, R.string.close) {
          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
          }
        };
    mDrawerToggle.syncState();
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Intent intentToReg = new Intent(ActivityMain.this,ActivityReg.class );
    // startActivity(intentToReg);

    UmengUpdateAgent.update(this);
  }