package com.minggo.plutoandroidexample.activity;
import android.app.ActivityManager;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.baidu.mobstat.StatService;
import com.minggo.pluto.*;
import com.minggo.pluto.activity.PlutoActivity;
import com.minggo.pluto.dialog.*;
import com.minggo.pluto.util.*;
import com.minggo.plutoandroidexample.R;
import com.minggo.plutoandroidexample.common.*;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends PlutoActivity
implements NavigationView.OnNavigationItemSelectedListener, OnClickListener {
@BindView(R.id.tv_license)
public TextView LicenseTv;
private PlutoDialog showLicenseDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
StatService.setDebugOn(true);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
initUI();
//throw new NullPointerException();
}
private void initUI() {
showLicenseDialog = new PlutoDialog(this, PlutoDialog.TEXT_ONLIY, "MIT License\n" +
"\n" +
"Copyright (c) 2017 minggo \n" +
"email <minggo8en@gmail.com>\n" +
"\n" +
"Permission is hereby granted, free of charge, to any person obtaining a copy\n" +
"of this software and associated documentation files (the \"Software\"), to deal\n" +
"in the Software without restriction, including without limitation the rights\n" +
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n" +
"copies of the Software, and to permit persons to whom the Software is\n" +
"furnished to do so, subject to the following conditions:\n" +
"\n" +
"The above copyright notice and this permission notice shall be included in all\n" +
"copies or substantial portions of the Software.\n" +
"\n" +
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" +
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" +
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" +
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" +
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n" +
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" +
"SOFTWARE.");
showLicenseDialog.setCancelable(true);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_pluto_activity) {
startActivity(new Intent(this,PlutoActivityExample.class));
} else if (id == R.id.nav_pluto_fragment) {
startActivity(new Intent(this,PlutoFragmentExample.class));
} else if (id == R.id.nav_pluto_dialog) {
startActivity(new Intent(this,PlutoDialogExample.class));
} else if (id == R.id.nav_pluto_engine) {
startActivity(new Intent(this,PlutoAPIEngineExample.class));
} else if (id == R.id.nav_pluto_image_framework) {
startActivity(new Intent(this,PlutoImageFrameworkExample.class));
} else if (id == R.id.nav_pluto_network){
startActivity(new Intent(this,PlutoNetworkExample.class));
} else if (id == R.id.nav_pluto_file_cache){
startActivity(new Intent(this,PlutoFileCacheExample.class));
} else if (id == R.id.nav_pluto_db_cache){
startActivity(new Intent(this,PlutoORMDBFrameworkExample.class));
} else if (id == R.id.nav_pluto_utils){
startActivity(new Intent(this,PlutoUtilsActivity.class));
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
@OnClick(R.id.tv_license)
public void onClick(View view) {
LogUtils.info(getClass().getSimpleName(), "点击进来了");
showLicenseDialog.show();
}
@Override
protected void onResume() {
super.onResume();
StatService.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
StatService.onPause(this);
}
}