package de.thedevstack.conversationsplus.ui; import android.app.Activity; import android.os.Bundle; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; import de.thedevstack.android.logcat.tasks.ReadLogCatAsyncTask; import de.thedevstack.conversationsplus.ui.listeners.LogCatOutputCopyOnClickListener; import de.thedevstack.conversationsplus.utils.ClipboardUtil; import eu.siacs.conversations.R; /** * Activity to display the logcat output. */ public class LogCatOutputActivity extends Activity { /** * List adapter containing the logcat entries. */ private LogCatArrayAdapter logCatArrayAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_logcatoutput); ListView lv = (ListView)findViewById(R.id.actLogInfoOutput); this.logCatArrayAdapter = new LogCatArrayAdapter(this, R.layout.list_item_logcatoutput); lv.setAdapter(this.logCatArrayAdapter); new ReadLogCatAsyncTask(this.logCatArrayAdapter).execute(); Button copyButton = (Button) findViewById(R.id.actLogOutputCopyButton); copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this.logCatArrayAdapter)); registerForContextMenu(lv); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.add(0, 123456789, 0, R.string.cplus_copy_item); } @Override public boolean onContextItemSelected(MenuItem item) { if (123456789 == item.getItemId()) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); String itemText = this.logCatArrayAdapter.getItems().get(info.position); ClipboardUtil.copyToClipboard(itemText); return true; } return super.onContextItemSelected(item); } }