/*
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.mobile.activities.logs;
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import org.openmrs.mobile.R;
import org.openmrs.mobile.activities.ACBaseFragment;
public class LogsFragment extends ACBaseFragment<LogsContract.Presenter> implements LogsContract.View{
private TextView tvLogs;
private FloatingActionButton fab;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_logs, container, false);
tvLogs = (TextView) root.findViewById(R.id.tvLogs);
fab = (FloatingActionButton) root.findViewById(R.id.fab);
return root;
}
public void attachLogsToTextView(String logs) {
tvLogs.setText(logs);
}
public void fabCopyAll(String textLogs){
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setClipboard(getContext() , textLogs);
Toast.makeText(getContext() , "Logs copied to clipboard",
Toast.LENGTH_SHORT).show();
}
});
}
@SuppressWarnings("deprecation")
private void setClipboard(Context context, String text) {
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", text);
clipboard.setPrimaryClip(clip);
}
}
public static LogsFragment newInstance() {
return new LogsFragment();
}
}