package com.catchingnow.tinyclipboardmanager;

import android.content.ClipboardManager;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;


public class ActivityGetShareText extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //receive system's text share
        Intent intent = getIntent();
        if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) {
            copyText(intent.getStringExtra(Intent.EXTRA_TEXT));
            return;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            finishAndRemoveTask();
        } else {
            finish();
        }
    }

    protected void copyText(String clips) {
        if (clips == null) {
            return;
        }
        if ("".equals(clips)) {
            return;
        }
        //copy clips to clipboard
        ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        cb.setText(clips);

        if (clips.length() > 15) {
            clips = clips.substring(0, 15) + "…";
        }
        Toast.makeText(this,
                getString(R.string.toast_front_string) + clips + "\n" + getString(R.string.toast_end_string),
                Toast.LENGTH_LONG
        ).show();

    }

}

@@ -59,32 +59,100 @@
 oid.
-content.ClipboardManager
+app.ActivityManager;%0Aimport android.content.ClipboardManager;%0Aimport android.content.Context
 ;%0Aim
@@ -284,64 +284,8 @@
 le;%0A
-import android.view.Menu;%0Aimport android.view.MenuItem;%0A
 impo
@@ -1038,17 +1038,16 @@
 ing clip
-s
 ) %7B%0A    
@@ -1058,17 +1058,16 @@
 if (clip
-s
  == null
@@ -1126,17 +1126,16 @@
 als(clip
-s
 )) %7B%0A   
@@ -1308,11 +1308,279 @@
 clip
-s
 );
+%0A%0A        //check service statues%0A        //if no service, manually add clip to db%0A        if (!isMyServiceRunning(CBWatcherService.class)) %7B%0A            Storage db = Storage.getInstance(this);%0A            db.modifyClip(null, clip, Storage.NOTIFICATION_VIEW);%0A        %7D
 %0A%0A  
@@ -1593,17 +1593,16 @@
 if (clip
-s
 .length(
@@ -1631,17 +1631,15 @@
 clip
-s
  = clip
-s
 .sub
@@ -1759,17 +1759,16 @@
 ) + clip
-s
  + %22%5Cn%22 
@@ -1867,10 +1867,440 @@
 %0A    %7D%0A%0A
+    private boolean isMyServiceRunning(Class%3C?%3E serviceClass) %7B%0A        ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);%0A        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) %7B%0A            if (serviceClass.getName().equals(service.service.getClassName())) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A
 %7D%0A

update db when service closed.