NetGuard/app/src/main/java/eu/faircode/netguard/ActivityLog.java

92 lines
2.8 KiB
Java
Raw Normal View History

2016-01-05 12:40:02 +00:00
package eu.faircode.netguard;
/*
This file is part of NetGuard.
NetGuard is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NetGuard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2015-2016 by Marcel Bokhorst (M66B)
*/
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
2016-01-05 21:53:22 +00:00
import android.view.Menu;
import android.view.MenuInflater;
2016-01-05 12:40:02 +00:00
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;
2016-01-05 12:40:02 +00:00
public class ActivityLog extends AppCompatActivity {
private ListView lvLog;
private DatabaseHelper dh;
private DatabaseHelper.LogChangedListener listener = new DatabaseHelper.LogChangedListener() {
@Override
2016-01-05 21:53:22 +00:00
public void onChanged() {
2016-01-05 12:40:02 +00:00
runOnUiThread(new Runnable() {
@Override
public void run() {
LogAdapter adapter = new LogAdapter(ActivityLog.this, dh.getLog());
lvLog.setAdapter(adapter);
}
});
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
Util.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.logview);
getSupportActionBar().setTitle(R.string.title_log);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
dh = new DatabaseHelper(this);
lvLog = (ListView) findViewById(R.id.lvLog);
LogAdapter adapter = new LogAdapter(this, dh.getLog());
lvLog.setAdapter(adapter);
DatabaseHelper.addLogChangedListener(listener);
Toast.makeText(this, getString(R.string.title_log_info), Toast.LENGTH_SHORT).show();
2016-01-05 12:40:02 +00:00
}
@Override
protected void onDestroy() {
DatabaseHelper.removeLocationChangedListener(listener);
dh.close();
super.onDestroy();
}
2016-01-05 21:53:22 +00:00
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.log, menu);
return true;
}
2016-01-05 12:40:02 +00:00
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
2016-01-05 21:53:22 +00:00
case R.id.menu_clear:
dh.clear();
return true;
2016-01-05 12:40:02 +00:00
}
return super.onOptionsItemSelected(item);
}
}