Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Android project for interacting with android clipboard service via shell
  • Loading branch information
majido committed Aug 24, 2012
0 parents commit 7cf8401
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
target
27 changes: 27 additions & 0 deletions AndroidManifest.xml
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cm.android" android:versionCode="1" android:versionName="1.0-SNAPSHOT">

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloAndroidActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".ClipboardServiceFront"
android:exported="true"
android:enabled="true">
</service>
<service android:name=".ClipperReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<data android:scheme="clipper" android:host="*" android:mimeType="*/*"/>
</intent-filter>
</service>

</application>

</manifest>

3 changes: 3 additions & 0 deletions default.properties
@@ -0,0 +1,3 @@
# File used by Eclipse to determine the target system
# Project target.
target=android-10
54 changes: 54 additions & 0 deletions pom.xml
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cm.android</groupId>
<artifactId>clipboard-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>clipboard-service</name>

<properties>
<platform.version>2.3.3</platform.version>
<android.sdk.path>/Users/majidv/android-sdk-macosx/</android.sdk.path>
</properties>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<platform>10</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Binary file added res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions res/layout/main.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
5 changes: 5 additions & 0 deletions res/values/strings.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello clipboard-service!</string>
<string name="app_name">clipboard-service</string>
</resources>
51 changes: 51 additions & 0 deletions src/main/java/com/cm/android/ClipboardServiceFront.java
@@ -0,0 +1,51 @@
package com.cm.android;

import android.text.ClipboardManager;
import android.app.IntentService;
import android.content.Intent;

import android.util.Log;

public class ClipboardServiceFront extends IntentService {
private static String TAG = "Clipboard service";



private static String ACTION_GET = "get";
private static String ACTION_SET = "set";

private static String EXTRA_TEXT = "text";



/**
* A constructor is required, and must call the super IntentService(String)
* constructor with a name for the worker thread.
*/
public ClipboardServiceFront() {
super("ClipboardServiceFront");

}

/**
* The IntentService calls this method from the default worker thread with
* the intent that started the service. When this method returns, IntentService
* stops the service, as appropriate.
*/
@Override
protected void onHandleIntent(Intent intent) {
Log.i(TAG, "Inside intent handler!");
Log.i(TAG, "ACTION:"+intent.getAction());
Log.i(TAG, "Text:"+ intent.getStringExtra(EXTRA_TEXT));

ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (ACTION_SET.equals(intent.getAction())) {
Log.i(TAG, "Setting text into clipboard");
cb.setText( intent.getStringExtra(EXTRA_TEXT));
} else if (ACTION_GET.equals( intent.getAction()) ) {
String clip = cb.getText().toString();
Log.i(TAG, "Got this from clipboard:"+clip);

}
}
}
37 changes: 37 additions & 0 deletions src/main/java/com/cm/android/ClipperReceiver.java
@@ -0,0 +1,37 @@
package com.cm.android;

import android.text.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;

import android.util.Log;
/* Same implementatio just listen to broadcasts */
public class ClipperReceiver extends BroadcastReceiver {
private static String TAG = "Clipboard receiver";


private static String ACTION_GET = "get";
private static String ACTION_SET = "set";

private static String EXTRA_TEXT = "text";

@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Inside intent handler!");
Log.i(TAG, "ACTION:"+ intent.getAction());
Log.i(TAG, "Text:"+ intent.getStringExtra(EXTRA_TEXT));

ClipboardManager cb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

if (ACTION_SET.equals(intent.getAction())) {
Log.i(TAG, "Setting text into clipboard");
cb.setText( intent.getStringExtra(EXTRA_TEXT));
} else if (ACTION_GET.equals( intent.getAction()) ) {
String clip = cb.getText().toString();
Log.i(TAG, "Got this from clipboard:" + clip);
}

}

}
25 changes: 25 additions & 0 deletions src/main/java/com/cm/android/HelloAndroidActivity.java
@@ -0,0 +1,25 @@
package com.cm.android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class HelloAndroidActivity extends Activity {

private static String TAG = "clipboard-service";

/**
* Called when the activity is first created.
* @param savedInstanceState If the activity is being re-initialized after
* previously being shut down then this Bundle contains the data it most
* recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
setContentView(R.layout.main);
}

}

0 comments on commit 7cf8401

Please sign in to comment.