Gitlab@AEI Hannover will go down for maintenance on 2020-09-21 at 4:00 UTC. The service will be unavailable for up to 24 hours. If you have questions about this please contact atlas_admin@aei.mpg.de

Commit 8f5347f3 authored by Isira Seneviratne's avatar Isira Seneviratne

Remove old EventLogActivity and EventLogActivityTabListener classes.

parent 35cb8761
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?><!--
This file is part of BOINC.
http://boinc.berkeley.edu
Copyright (C) 2020 University of California
BOINC is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
BOINC 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BOINC. If not, see <http://www.gnu.org/licenses/>.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.berkeley.boinc"
android:installLocation="internalOnly">
......@@ -43,9 +60,12 @@
android:largeHeap="true"
android:theme="@style/AppTheme">
<activity
android:name=".ui.eventlog.EventLogActivity2"
android:label="R.string.menu_eventlog"
android:theme="@style/AppTheme.NoActionBar" />
android:name=".ui.eventlog.EventLogActivity"
android:label="@string/menu_eventlog">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="edu.berkeley.boinc.BOINCActivity" />
</activity>
<activity
android:name=".SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
......@@ -78,11 +98,6 @@
<activity
android:name=".attach.BatchConflictListActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".ui.eventlog.EventLogActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="edu.berkeley.boinc.BOINCActivity" />
</activity>
<service
android:name=".client.Monitor"
......
/*
* This file is part of BOINC.
* http://boinc.berkeley.edu
* Copyright (C) 2020 University of California
*
* BOINC is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* BOINC 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
*/
package edu.berkeley.boinc.ui.eventlog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBar.Tab;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import edu.berkeley.boinc.R;
import edu.berkeley.boinc.adapter.ClientLogRecyclerViewAdapter;
import edu.berkeley.boinc.adapter.GuiLogRecyclerViewAdapter;
import edu.berkeley.boinc.client.IMonitor;
import edu.berkeley.boinc.client.Monitor;
import edu.berkeley.boinc.rpc.Message;
import edu.berkeley.boinc.utils.Logging;
public class EventLogActivity extends AppCompatActivity {
private IMonitor monitor;
private boolean mIsBound = false;
public RecyclerView clientLogList;
public ClientLogRecyclerViewAdapter clientLogRecyclerViewAdapter;
public List<Message> clientLogData = new ArrayList<>();
public RecyclerView guiLogList;
public GuiLogRecyclerViewAdapter guiLogRecyclerViewAdapter;
public List<String> guiLogData = new ArrayList<>();
private List<EventLogActivityTabListener<?>> listeners = new ArrayList<>();
static final int GUI_LOG_TAB_ACTIVE = 1;
static final int CLIENT_LOG_TAB_ACTIVE = 2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setup action bar
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(R.string.menu_eventlog);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
EventLogActivityTabListener<EventLogClientFragment> clientListener =
new EventLogActivityTabListener<>(this, getString(R.string.eventlog_client_header), EventLogClientFragment.class);
listeners.add(clientListener);
Tab tab = actionBar.newTab()
.setText(R.string.eventlog_client_header)
.setTabListener(clientListener);
actionBar.addTab(tab);
EventLogActivityTabListener<EventLogGuiFragment> guiListener =
new EventLogActivityTabListener<>(this, getString(R.string.eventlog_gui_header), EventLogGuiFragment.class);
listeners.add(guiListener);
tab = actionBar.newTab()
.setText(R.string.eventlog_gui_header)
.setTabListener(guiListener);
actionBar.addTab(tab);
actionBar.setDisplayHomeAsUpEnabled(true);
doBindService();
}
@Override
protected void onDestroy() {
doUnbindService();
super.onDestroy();
}
/*
* Service binding part
* only necessary, when function on monitor instance has to be called
*/
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
if(Logging.VERBOSE) {
Log.d(Logging.TAG, "EventLogActivity onServiceConnected");
}
monitor = IMonitor.Stub.asInterface(service);
mIsBound = true;
// initialize default fragment
((EventLogClientFragment) getSupportFragmentManager().findFragmentByTag(getString(R.string.eventlog_client_header))).init();
}
@Override
public void onServiceDisconnected(ComponentName className) {
monitor = null;
mIsBound = false;
}
};
private void doBindService() {
if(!mIsBound) {
getApplicationContext().bindService(new Intent(this, Monitor.class), mConnection, 0); //calling within Tab needs getApplicationContext() for bindService to work!
}
}
private void doUnbindService() {
if(mIsBound) {
getApplicationContext().unbindService(mConnection);
mIsBound = false;
}
}
public IMonitor getMonitorService() {
if(!mIsBound && Logging.WARNING) {
Log.w(Logging.TAG, "Fragment trying to obtain service reference, but Monitor not bound in EventLogActivity");
}
return monitor;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.eventlog_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.refresh:
updateCurrentFragment();
return true;
case R.id.email_to:
onEmailTo();
return true;
case R.id.copy:
onCopy();
return true;
}
return super.onOptionsItemSelected(item);
}
private int getActiveLog() {
for(EventLogActivityTabListener<?> tmp : listeners) {
if(tmp.currentlySelected) {
if(tmp.mClass == EventLogClientFragment.class) {
return CLIENT_LOG_TAB_ACTIVE;
}
else if(tmp.mClass == EventLogGuiFragment.class) {
return GUI_LOG_TAB_ACTIVE;
}
}
}
return -1;
}
private void updateCurrentFragment() {
for(EventLogActivityTabListener<?> tmp : listeners) {
if(tmp.currentlySelected) {
if(tmp.mClass == EventLogClientFragment.class) {
((EventLogClientFragment) tmp.mFragment).update();
}
else if(tmp.mClass == EventLogGuiFragment.class) {
((EventLogGuiFragment) tmp.mFragment).update();
}
break;
}
}
}
private void onCopy() {
try {
ClipboardManager clipboard = ContextCompat.getSystemService(this, ClipboardManager.class);
ClipData clipData = ClipData.newPlainText("log", getLogDataAsString());
clipboard.setPrimaryClip(clipData);
Toast.makeText(getApplicationContext(), R.string.eventlog_copy_toast, Toast.LENGTH_SHORT).show();
}
catch(Exception e) {
if(Logging.WARNING) {
Log.w(Logging.TAG, "onCopy failed");
}
}
}
private void onEmailTo() {
try {
String emailText = getLogDataAsString();
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
// Put together the email intent
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.eventlog_email_subject));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
// Send it off to the Activity-Chooser
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
catch(Exception e) {
if(Logging.WARNING) {
Log.w(Logging.TAG, "onEmailTo failed");
}
}
}
// returns the content of the log as string
// clientLog = true: client log
// clientlog = false: gui log
private String getLogDataAsString() {
StringBuilder text = new StringBuilder();
int type = getActiveLog();
if(type == CLIENT_LOG_TAB_ACTIVE) {
text.append(getString(R.string.eventlog_client_header)).append("\n\n");
for(int index = 0; index < clientLogList.getChildCount(); index++) {
text.append(clientLogRecyclerViewAdapter.getDateTimeString(index));
text.append("|");
text.append(clientLogRecyclerViewAdapter.getProject(index));
text.append("|");
text.append(clientLogRecyclerViewAdapter.getMessage(index));
text.append("\n");
}
}
else if(type == GUI_LOG_TAB_ACTIVE) {
text.append(getString(R.string.eventlog_gui_header)).append("\n\n");
for(String line : guiLogData) {
text.append(line);
text.append("\n");
}
}
else if(Logging.WARNING) {
Log.w(Logging.TAG, "EventLogActivity could not determine which log active.");
}
return text.toString();
}
}
/*
* This file is part of BOINC.
* http://boinc.berkeley.edu
* Copyright (C) 2020 University of California
*
* BOINC is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* BOINC 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
*/
package edu.berkeley.boinc.ui.eventlog
import android.content.*
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.tabs.TabLayoutMediator
import edu.berkeley.boinc.R
import edu.berkeley.boinc.adapter.ClientLogRecyclerViewAdapter
import edu.berkeley.boinc.client.IMonitor
import edu.berkeley.boinc.client.Monitor
import edu.berkeley.boinc.databinding.ActivityEventLogBinding
import edu.berkeley.boinc.rpc.Message
import edu.berkeley.boinc.utils.Logging
import java.util.*
class EventLogActivity : AppCompatActivity() {
private lateinit var binding: ActivityEventLogBinding
private var monitor: IMonitor? = null
private var mIsBound = false
lateinit var clientLogList: RecyclerView
lateinit var clientLogRecyclerViewAdapter: ClientLogRecyclerViewAdapter
val clientLogData: MutableList<Message> = ArrayList()
val guiLogData: List<String> = ArrayList()
private val mConnection: ServiceConnection = object : ServiceConnection {
override fun onServiceConnected(className: ComponentName, service: IBinder) {
if (Logging.VERBOSE) {
Log.d(Logging.TAG, "EventLogActivity onServiceConnected")
}
monitor = IMonitor.Stub.asInterface(service)
mIsBound = true
// initialize default fragment
(supportFragmentManager.findFragmentByTag("f0") as EventLogClientFragment).init()
}
override fun onServiceDisconnected(className: ComponentName) {
monitor = null
mIsBound = false
}
}
val monitorService: IMonitor
get() {
if (!mIsBound && Logging.WARNING) {
Log.w(Logging.TAG, "Fragment trying to obtain service reference, but Monitor" +
" not bound in EventLogActivity")
}
return monitor!!
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityEventLogBinding.inflate(layoutInflater)
setContentView(binding.root)
val eventLogPagerAdapter = EventLogPagerAdapter(this)
binding.viewPager.adapter = eventLogPagerAdapter
TabLayoutMediator(binding.tabs, binding.viewPager) { tab, position ->
tab.text = if (position == 0)
getString(R.string.eventlog_client_header)
else
getString(R.string.eventlog_gui_header)
}.attach()
doBindService()
}
override fun onDestroy() {
doUnbindService()
super.onDestroy()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.eventlog_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.refresh -> {
updateCurrentFragment()
return true
}
R.id.email_to -> {
onEmailTo()
return true
}
R.id.copy -> {
onCopy()
return true
}
}
return super.onOptionsItemSelected(item)
}
private fun doBindService() {
if (!mIsBound) {
applicationContext.bindService(Intent(this, Monitor::class.java), mConnection, 0) //calling within Tab needs getApplicationContext() for bindService to work!
}
}
private fun doUnbindService() {
if (mIsBound) {
applicationContext.unbindService(mConnection)
mIsBound = false
}
}
private fun updateCurrentFragment() {
val currentFragment = supportFragmentManager.findFragmentByTag("f${binding.viewPager.currentItem}")
if (currentFragment is EventLogClientFragment) {
currentFragment.update()
} else if (currentFragment is EventLogGuiFragment) {
currentFragment.update()
}
}
private fun onCopy() {
try {
val clipboard = getSystemService<ClipboardManager>()!!
val clipData = ClipData.newPlainText("log", getLogDataAsString())
clipboard.setPrimaryClip(clipData)
Toast.makeText(applicationContext, R.string.eventlog_copy_toast, Toast.LENGTH_SHORT).show()
} catch (e: Exception) {
if (Logging.WARNING) {
Log.w(Logging.TAG, "onCopy failed")
}
}
}
private fun onEmailTo() {
try {
val emailText = getLogDataAsString()
val emailIntent = Intent(Intent.ACTION_SEND)
// Put together the email intent
emailIntent.type = "plain/text"
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.eventlog_email_subject))
emailIntent.putExtra(Intent.EXTRA_TEXT, emailText)
// Send it off to the Activity-Chooser
startActivity(Intent.createChooser(emailIntent, "Send mail..."))
} catch (e: Exception) {
if (Logging.WARNING) {
Log.w(Logging.TAG, "onEmailTo failed")
}
}
}
// returns the content of the log as string
// clientLog = true: client log
// clientlog = false: gui log
private fun getLogDataAsString(): String {
val text = StringBuilder()
val type = binding.viewPager.currentItem
when {
type == 0 -> {
text.append(getString(R.string.eventlog_client_header)).append("\n\n")
for (index in 0 until clientLogList.childCount) {
text.append(clientLogRecyclerViewAdapter.getDateTimeString(index))
text.append("|")
text.append(clientLogRecyclerViewAdapter.getProject(index))
text.append("|")
text.append(clientLogRecyclerViewAdapter.getMessage(index))
text.append("\n")
}
}
type == 1 -> {
text.append(getString(R.string.eventlog_gui_header)).append("\n\n")
for (line in guiLogData) {
text.append(line)
text.append("\n")
}
}
Logging.WARNING -> {
Log.w(Logging.TAG, "EventLogActivity could not determine which log active.")
}
}
return text.toString()
}
}
/*
* This file is part of BOINC.
* http://boinc.berkeley.edu
* Copyright (C) 2020 University of California
*
* BOINC is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* BOINC 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
*/
package edu.berkeley.boinc.ui.eventlog
import android.os.Bundle
import android.view.Menu
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.tabs.TabLayoutMediator
import edu.berkeley.boinc.R
import edu.berkeley.boinc.databinding.ActivityEventLog2Binding
class EventLogActivity2 : AppCompatActivity() {
private lateinit var binding: ActivityEventLog2Binding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityEventLog2Binding.inflate(layoutInflater)
setContentView(binding.root)
val eventLogPagerAdapter = EventLogPagerAdapter(this)
binding.viewPager.adapter = eventLogPagerAdapter
TabLayoutMediator(binding.tabs, binding.viewPager) { tab, position ->
tab.text = if (position == 0)
getString(R.string.eventlog_client_header)
else
getString(R.string.eventlog_gui_header)
}.attach()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.eventlog_menu, menu)
return true
}
}
/*
* This file is part of BOINC.
* http://boinc.berkeley.edu
* Copyright (C) 2013 University of California
*
* BOINC is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* BOINC 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
*/
package edu.berkeley.boinc.ui.eventlog;