1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.textclassifier.notification; 18 19 import android.app.Activity; 20 import android.content.ClipData; 21 import android.content.ClipboardManager; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.text.TextUtils; 25 import android.util.Log; 26 import android.widget.Toast; 27 import javax.annotation.Nullable; 28 29 /** Handles the copy code action. */ 30 public class CopyCodeActivity extends Activity { 31 private static final String TAG = "CopyCodeActivity"; 32 33 @Override onCreate(@ullable Bundle savedInstanceState)34 protected void onCreate(@Nullable Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 handleIntent(); 37 finish(); 38 } 39 handleIntent()40 private void handleIntent() { 41 String code = getIntent().getStringExtra(Intent.EXTRA_TEXT); 42 if (TextUtils.isEmpty(code)) { 43 Log.w(TAG, "handleIntent: empty code"); 44 return; 45 } 46 ClipboardManager clipboardManager = getSystemService(ClipboardManager.class); 47 ClipData clipData = ClipData.newPlainText(null, code); 48 clipboardManager.setPrimaryClip(clipData); 49 Toast.makeText( 50 getApplicationContext(), R.string.tc_notif_code_copied_to_clipboard, Toast.LENGTH_SHORT) 51 .show(); 52 } 53 } 54