diff options
Diffstat (limited to '')
77 files changed, 2280 insertions, 2337 deletions
diff --git a/libs/MemorizingTrustManager/AndroidManifest.xml b/libs/MemorizingTrustManager/AndroidManifest.xml index c125afe42..4d3a2b41c 100644 --- a/libs/MemorizingTrustManager/AndroidManifest.xml +++ b/libs/MemorizingTrustManager/AndroidManifest.xml @@ -1,11 +1,12 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="de.duenndns.ssl" - android:versionCode="1" - android:versionName="1.0"> + package="de.duenndns.ssl" + android:versionCode="1" + android:versionName="1.0"> - <application android:label="MemorizingTrustManager"> - <activity android:name="de.duenndns.ssl.MemorizingActivity" - android:theme="@android:style/Theme.Translucent.NoTitleBar" /> - </application> + <application android:label="MemorizingTrustManager"> + <activity + android:name="de.duenndns.ssl.MemorizingActivity" + android:theme="@android:style/Theme.Translucent.NoTitleBar" /> + </application> </manifest> diff --git a/libs/MemorizingTrustManager/ant.properties b/libs/MemorizingTrustManager/ant.properties index ee52d86d9..21ef4e321 100644 --- a/libs/MemorizingTrustManager/ant.properties +++ b/libs/MemorizingTrustManager/ant.properties @@ -2,13 +2,10 @@ # # This file must be checked in Version Control Systems, as it is # integral to the build system of your project. - # This file is only used by the Ant script. - # You can use this to override default values such as # 'source.dir' for the location of your java source folder and # 'out.dir' for the location of your output folder. - # You can also use it define how the release builds are signed by declaring # the following properties: # 'key.store' for the location of your keystore and diff --git a/libs/MemorizingTrustManager/build.gradle b/libs/MemorizingTrustManager/build.gradle index a3b4c5106..12072b81f 100644 --- a/libs/MemorizingTrustManager/build.gradle +++ b/libs/MemorizingTrustManager/build.gradle @@ -1,32 +1,32 @@ buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' - } + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.2' + } } apply plugin: 'android-library' android { - compileSdkVersion 19 - buildToolsVersion "19.1" - defaultConfig { - minSdkVersion 7 - targetSdkVersion 19 - } + compileSdkVersion 19 + buildToolsVersion "19.1" + defaultConfig { + minSdkVersion 7 + targetSdkVersion 19 + } - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - resources.srcDirs = ['src'] - aidl.srcDirs = ['src'] - renderscript.srcDirs = ['src'] - res.srcDirs = ['res'] - assets.srcDirs = ['assets'] - } - } + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + resources.srcDirs = ['src'] + aidl.srcDirs = ['src'] + renderscript.srcDirs = ['src'] + res.srcDirs = ['res'] + assets.srcDirs = ['assets'] + } + } } diff --git a/libs/MemorizingTrustManager/build.xml b/libs/MemorizingTrustManager/build.xml index 06cf485c1..15b0b0104 100644 --- a/libs/MemorizingTrustManager/build.xml +++ b/libs/MemorizingTrustManager/build.xml @@ -50,9 +50,8 @@ <!-- quick check on sdk.dir --> <fail - message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." - unless="sdk.dir" - /> + message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." + unless="sdk.dir" /> <!-- Import per project custom build rules if present at the root of the project. diff --git a/libs/MemorizingTrustManager/example/AndroidManifest.xml b/libs/MemorizingTrustManager/example/AndroidManifest.xml index cdc0450b3..ebc664d65 100644 --- a/libs/MemorizingTrustManager/example/AndroidManifest.xml +++ b/libs/MemorizingTrustManager/example/AndroidManifest.xml @@ -1,20 +1,22 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="de.duenndns.mtmexample" - android:versionCode="1" - android:versionName="1.0"> - + package="de.duenndns.mtmexample" + android:versionCode="1" + android:versionName="1.0"> + <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.INTERNET" /> - <application android:label="@string/app_name" android:icon="@android:drawable/ic_lock_lock"> + <application + android:label="@string/app_name" + android:icon="@android:drawable/ic_lock_lock"> <activity android:name=".MTMExample" android:configChanges="keyboardHidden|orientation|screenSize|screenLayout" - android:label="@string/app_name" > + android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -22,8 +24,9 @@ </intent-filter> </activity> - <!-- ADD THE FOLLOWING TO YOUR MANIFEST: --> - <activity android:name="de.duenndns.ssl.MemorizingActivity" - android:theme="@android:style/Theme.Translucent.NoTitleBar" /> + <!-- ADD THE FOLLOWING TO YOUR MANIFEST: --> + <activity + android:name="de.duenndns.ssl.MemorizingActivity" + android:theme="@android:style/Theme.Translucent.NoTitleBar" /> </application> </manifest> diff --git a/libs/MemorizingTrustManager/example/ant.properties b/libs/MemorizingTrustManager/example/ant.properties index 27fcaadd8..2f48b3655 100644 --- a/libs/MemorizingTrustManager/example/ant.properties +++ b/libs/MemorizingTrustManager/example/ant.properties @@ -2,17 +2,13 @@ # # This file must be checked in Version Control Systems, as it is # integral to the build system of your project. - # This file is only used by the Ant script. - # You can use this to override default values such as # 'source.dir' for the location of your java source folder and # 'out.dir' for the location of your output folder. - # You can also use it define how the release builds are signed by declaring # the following properties: # 'key.store' for the location of your keystore and # 'key.alias' for the name of the key to use. # The password will be asked during the build when you use the 'release' target. - application.package=de.duenndns.mtmexample diff --git a/libs/MemorizingTrustManager/example/build.gradle b/libs/MemorizingTrustManager/example/build.gradle index 00bfe99e2..a07fbe87b 100644 --- a/libs/MemorizingTrustManager/example/build.gradle +++ b/libs/MemorizingTrustManager/example/build.gradle @@ -1,23 +1,23 @@ apply plugin: 'android' dependencies { - compile rootProject + compile rootProject } android { - compileSdkVersion 19 - buildToolsVersion "19.1" - defaultConfig { - minSdkVersion 7 - targetSdkVersion 19 - } + compileSdkVersion 19 + buildToolsVersion "19.1" + defaultConfig { + minSdkVersion 7 + targetSdkVersion 19 + } - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - res.srcDirs = ['res'] - } - } + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + res.srcDirs = ['res'] + } + } } diff --git a/libs/MemorizingTrustManager/example/build.xml b/libs/MemorizingTrustManager/example/build.xml index cdc74917d..0c61a2917 100644 --- a/libs/MemorizingTrustManager/example/build.xml +++ b/libs/MemorizingTrustManager/example/build.xml @@ -50,9 +50,8 @@ <!-- quick check on sdk.dir --> <fail - message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." - unless="sdk.dir" - /> + message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." + unless="sdk.dir" /> <!-- Import per project custom build rules if present at the root of the project. diff --git a/libs/MemorizingTrustManager/example/project.properties b/libs/MemorizingTrustManager/example/project.properties index 3692949fd..be830d977 100644 --- a/libs/MemorizingTrustManager/example/project.properties +++ b/libs/MemorizingTrustManager/example/project.properties @@ -6,7 +6,6 @@ # To customize properties used by the Ant build system use, # "ant.properties", and override values to adapt the script to your # project structure. - android.library.reference.1=../ # Project target. target=android-19 diff --git a/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml b/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml index dfef58b6c..4a08b6899 100644 --- a/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml +++ b/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml @@ -1,36 +1,36 @@ <?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" > - <EditText - android:id="@+id/url" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:hint="HTTPS address" - android:text="https://op-co.de/mtm/" - android:singleLine="true" - /> - <Button - android:id="@+id/connect" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="Connect" - /> - <TextView - android:id="@+id/content" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_weight="1" - android:text="Please enter a HTTPS URL and press 'Connect'!" - android:textSize="11pt" - /> - <Button - android:id="@+id/manage" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="Clean up Certificates" - android:onClick="onManage" - /> + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + <EditText + android:id="@+id/url" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:hint="HTTPS address" + android:text="https://op-co.de/mtm/" + android:singleLine="true" /> + + <Button + android:id="@+id/connect" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="Connect" /> + + <TextView + android:id="@+id/content" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="Please enter a HTTPS URL and press 'Connect'!" + android:textSize="11pt" /> + + <Button + android:id="@+id/manage" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="Clean up Certificates" + android:onClick="onManage" /> </LinearLayout> diff --git a/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/JULHandler.java b/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/JULHandler.java index 6d183eb60..2cd70d0c5 100644 --- a/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/JULHandler.java +++ b/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/JULHandler.java @@ -34,136 +34,146 @@ import java.util.logging.Logger; * If there are no {@code DebugLogSettings} configured, then all messages sent * to JUL will be logged. * </p> - * + * * @author Florian Schmaus - * */ @SuppressWarnings("deprecation") public class JULHandler extends Handler { - /** Implement this interface to toggle debug logging. - */ - public interface DebugLogSettings { - public boolean isDebugLogEnabled(); - } - - private static final String CLASS_NAME = JULHandler.class.getName(); - - /** - * The global LogManager configuration. - * <p> - * This configures: - * <ul> - * <li> JULHandler as the default handler for all log messages - * <li> A default log level FINEST (300). Meaning that log messages of a level 300 or higher a - * logged - * </ul> - * </p> - */ - private static final InputStream LOG_MANAGER_CONFIG = new StringBufferInputStream( + /** + * Implement this interface to toggle debug logging. + */ + public interface DebugLogSettings { + public boolean isDebugLogEnabled(); + } + + private static final String CLASS_NAME = JULHandler.class.getName(); + + /** + * The global LogManager configuration. + * <p> + * This configures: + * <ul> + * <li> JULHandler as the default handler for all log messages + * <li> A default log level FINEST (300). Meaning that log messages of a level 300 or higher a + * logged + * </ul> + * </p> + */ + private static final InputStream LOG_MANAGER_CONFIG = new StringBufferInputStream( // @formatter:off -"handlers = " + CLASS_NAME + '\n' + -".level = FINEST" -); + "handlers = " + CLASS_NAME + '\n' + + ".level = FINEST" + ); // @formatter:on - // Constants for Android vs. JUL debug level comparisons - private static final int FINE_INT = Level.FINE.intValue(); - private static final int INFO_INT = Level.INFO.intValue(); - private static final int WARN_INT = Level.WARNING.intValue(); - private static final int SEVE_INT = Level.SEVERE.intValue(); - - private static final Logger LOGGER = Logger.getLogger(CLASS_NAME); - - /** A formatter that creates output similar to Android's Log.x. */ - private static final Formatter FORMATTER = new Formatter() { - @Override - public String format(LogRecord logRecord) { - Throwable thrown = logRecord.getThrown(); - if (thrown != null) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw, false); - pw.write(logRecord.getMessage() + ' '); - thrown.printStackTrace(pw); - pw.flush(); - return sw.toString(); - } else { - return logRecord.getMessage(); - } - } - }; - - private static DebugLogSettings sDebugLogSettings; - private static boolean initialized = false; - - public static void initialize() { - try { - LogManager.getLogManager().readConfiguration(LOG_MANAGER_CONFIG); - initialized = true; - } catch (IOException e) { - Log.e("JULHandler", "Can not initialize configuration", e); - } - if (initialized) LOGGER.info("Initialzied java.util.logging logger"); - } - - public static void setDebugLogSettings(DebugLogSettings debugLogSettings) { - if (!isInitialized()) initialize(); - sDebugLogSettings = debugLogSettings; - } - - public static boolean isInitialized() { - return initialized; - } - - public JULHandler() { - setFormatter(FORMATTER); - } - - @Override - public void close() {} - - @Override - public void flush() {} - - @Override - public boolean isLoggable(LogRecord record) { - final boolean debugLog = sDebugLogSettings == null ? true : sDebugLogSettings - .isDebugLogEnabled(); - - if (record.getLevel().intValue() <= FINE_INT) { - return debugLog; - } - return true; - } - - /** JUL method that forwards log records to Android's LogCat. */ - @Override - public void publish(LogRecord record) { - if (!isLoggable(record)) return; - - final int priority = getAndroidPriority(record.getLevel()); - final String tag = substringAfterLastDot(record.getSourceClassName()); - final String msg = getFormatter().format(record); - - Log.println(priority, tag, msg); - } - - /** Helper to convert JUL verbosity levels to Android's Log. */ - private static int getAndroidPriority(Level level) { - int value = level.intValue(); - if (value >= SEVE_INT) { - return Log.ERROR; - } else if (value >= WARN_INT) { - return Log.WARN; - } else if (value >= INFO_INT) { - return Log.INFO; - } else { - return Log.DEBUG; - } - } - - /** Helper to extract short class names. */ - private static String substringAfterLastDot(String s) { - return s.substring(s.lastIndexOf('.') + 1).trim(); - } + // Constants for Android vs. JUL debug level comparisons + private static final int FINE_INT = Level.FINE.intValue(); + private static final int INFO_INT = Level.INFO.intValue(); + private static final int WARN_INT = Level.WARNING.intValue(); + private static final int SEVE_INT = Level.SEVERE.intValue(); + + private static final Logger LOGGER = Logger.getLogger(CLASS_NAME); + + /** + * A formatter that creates output similar to Android's Log.x. + */ + private static final Formatter FORMATTER = new Formatter() { + @Override + public String format(LogRecord logRecord) { + Throwable thrown = logRecord.getThrown(); + if (thrown != null) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw, false); + pw.write(logRecord.getMessage() + ' '); + thrown.printStackTrace(pw); + pw.flush(); + return sw.toString(); + } else { + return logRecord.getMessage(); + } + } + }; + + private static DebugLogSettings sDebugLogSettings; + private static boolean initialized = false; + + public static void initialize() { + try { + LogManager.getLogManager().readConfiguration(LOG_MANAGER_CONFIG); + initialized = true; + } catch (IOException e) { + Log.e("JULHandler", "Can not initialize configuration", e); + } + if (initialized) LOGGER.info("Initialzied java.util.logging logger"); + } + + public static void setDebugLogSettings(DebugLogSettings debugLogSettings) { + if (!isInitialized()) initialize(); + sDebugLogSettings = debugLogSettings; + } + + public static boolean isInitialized() { + return initialized; + } + + public JULHandler() { + setFormatter(FORMATTER); + } + + @Override + public void close() { + } + + @Override + public void flush() { + } + + @Override + public boolean isLoggable(LogRecord record) { + final boolean debugLog = sDebugLogSettings == null ? true : sDebugLogSettings + .isDebugLogEnabled(); + + if (record.getLevel().intValue() <= FINE_INT) { + return debugLog; + } + return true; + } + + /** + * JUL method that forwards log records to Android's LogCat. + */ + @Override + public void publish(LogRecord record) { + if (!isLoggable(record)) return; + + final int priority = getAndroidPriority(record.getLevel()); + final String tag = substringAfterLastDot(record.getSourceClassName()); + final String msg = getFormatter().format(record); + + Log.println(priority, tag, msg); + } + + /** + * Helper to convert JUL verbosity levels to Android's Log. + */ + private static int getAndroidPriority(Level level) { + int value = level.intValue(); + if (value >= SEVE_INT) { + return Log.ERROR; + } else if (value >= WARN_INT) { + return Log.WARN; + } else if (value >= INFO_INT) { + return Log.INFO; + } else { + return Log.DEBUG; + } + } + + /** + * Helper to extract short class names. + */ + private static String substringAfterLastDot(String s) { + return s.substring(s.lastIndexOf('.') + 1).trim(); + } } diff --git a/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/MTMExample.java b/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/MTMExample.java index 52e20dff6..31e37bd00 100644 --- a/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/MTMExample.java +++ b/libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/MTMExample.java @@ -28,116 +28,124 @@ import de.duenndns.ssl.MemorizingTrustManager; * Example to demonstrate the use of MemorizingTrustManager on HTTPS * sockets. */ -public class MTMExample extends Activity implements OnClickListener -{ - MemorizingTrustManager mtm; - - TextView content; - HostnameVerifier defaultverifier; - EditText urlinput; - String text; - Handler hdlr; - - /** Creates the Activity and registers a MemorizingTrustManager. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - JULHandler.initialize(); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - setContentView(R.layout.mtmexample); - - - // set up gui elements - findViewById(R.id.connect).setOnClickListener(this); - content = (TextView)findViewById(R.id.content); - urlinput = (EditText)findViewById(R.id.url); - - // register handler for background thread - hdlr = new Handler(); - - // Here, the MemorizingTrustManager is activated for HTTPS - try { - // set location of the keystore - MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks"); - - // register MemorizingTrustManager for HTTPS - SSLContext sc = SSLContext.getInstance("TLS"); - mtm = new MemorizingTrustManager(this); - sc.init(null, new X509TrustManager[] { mtm }, - new java.security.SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - HttpsURLConnection.setDefaultHostnameVerifier( - mtm.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())); - - // disable redirects to reduce possible confusion - HttpsURLConnection.setFollowRedirects(false); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** Updates the screen content from a background thread. */ - void setText(final String s, final boolean progress) { - text = s; - hdlr.post(new Runnable() { - public void run() { - content.setText(s); - setProgressBarIndeterminateVisibility(progress); - } - }); - } - - /** Spawns a new thread connecting to the specified URL. - * The result of the request is displayed on the screen. - * @param urlString a HTTPS URL to connect to. - */ - void connect(final String urlString) { - new Thread() { - public void run() { - try { - URL u = new URL(urlString); - HttpsURLConnection c = (HttpsURLConnection)u.openConnection(); - c.connect(); - setText("" + c.getResponseCode() + " " - + c.getResponseMessage(), false); - c.disconnect(); - } catch (Exception e) { - setText(e.toString(), false); - e.printStackTrace(); - } - } - }.start(); - } - - /** Reacts on the connect Button press. */ - @Override - public void onClick(View view) { - String url = urlinput.getText().toString(); - setText("Loading " + url, true); - setProgressBarIndeterminateVisibility(true); - connect(url); - } - - /** React on the "Manage Certificates" button press. */ - public void onManage(View view) { - final ArrayList<String> aliases = Collections.list(mtm.getCertificates()); - ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, aliases); - new AlertDialog.Builder(this).setTitle("Tap Certificate to Delete") - .setNegativeButton(android.R.string.cancel, null) - .setAdapter(adapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - try { - String alias = aliases.get(which); - mtm.deleteCertificate(alias); - setText("Deleted " + alias, false); - } catch (KeyStoreException e) { - e.printStackTrace(); - setText("Error: " + e.getLocalizedMessage(), false); - } - } - }) - .create().show(); - } +public class MTMExample extends Activity implements OnClickListener { + MemorizingTrustManager mtm; + + TextView content; + HostnameVerifier defaultverifier; + EditText urlinput; + String text; + Handler hdlr; + + /** + * Creates the Activity and registers a MemorizingTrustManager. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + JULHandler.initialize(); + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + setContentView(R.layout.mtmexample); + + + // set up gui elements + findViewById(R.id.connect).setOnClickListener(this); + content = (TextView) findViewById(R.id.content); + urlinput = (EditText) findViewById(R.id.url); + + // register handler for background thread + hdlr = new Handler(); + + // Here, the MemorizingTrustManager is activated for HTTPS + try { + // set location of the keystore + MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks"); + + // register MemorizingTrustManager for HTTPS + SSLContext sc = SSLContext.getInstance("TLS"); + mtm = new MemorizingTrustManager(this); + sc.init(null, new X509TrustManager[]{mtm}, + new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + HttpsURLConnection.setDefaultHostnameVerifier( + mtm.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())); + + // disable redirects to reduce possible confusion + HttpsURLConnection.setFollowRedirects(false); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Updates the screen content from a background thread. + */ + void setText(final String s, final boolean progress) { + text = s; + hdlr.post(new Runnable() { + public void run() { + content.setText(s); + setProgressBarIndeterminateVisibility(progress); + } + }); + } + + /** + * Spawns a new thread connecting to the specified URL. + * The result of the request is displayed on the screen. + * + * @param urlString a HTTPS URL to connect to. + */ + void connect(final String urlString) { + new Thread() { + public void run() { + try { + URL u = new URL(urlString); + HttpsURLConnection c = (HttpsURLConnection) u.openConnection(); + c.connect(); + setText("" + c.getResponseCode() + " " + + c.getResponseMessage(), false); + c.disconnect(); + } catch (Exception e) { + setText(e.toString(), false); + e.printStackTrace(); + } + } + }.start(); + } + + /** + * Reacts on the connect Button press. + */ + @Override + public void onClick(View view) { + String url = urlinput.getText().toString(); + setText("Loading " + url, true); + setProgressBarIndeterminateVisibility(true); + connect(url); + } + + /** + * React on the "Manage Certificates" button press. + */ + public void onManage(View view) { + final ArrayList<String> aliases = Collections.list(mtm.getCertificates()); + ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, aliases); + new AlertDialog.Builder(this).setTitle("Tap Certificate to Delete") + .setNegativeButton(android.R.string.cancel, null) + .setAdapter(adapter, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + try { + String alias = aliases.get(which); + mtm.deleteCertificate(alias); + setText("Deleted " + alias, false); + } catch (KeyStoreException e) { + e.printStackTrace(); + setText("Error: " + e.getLocalizedMessage(), false); + } + } + }) + .create().show(); + } } diff --git a/libs/MemorizingTrustManager/project.properties b/libs/MemorizingTrustManager/project.properties index c57400d00..7c444cd57 100644 --- a/libs/MemorizingTrustManager/project.properties +++ b/libs/MemorizingTrustManager/project.properties @@ -6,7 +6,6 @@ # To customize properties used by the Ant build system use, # "ant.properties", and override values to adapt the script to your # project structure. - android.library=true # Project target. target=android-19 diff --git a/libs/MemorizingTrustManager/src/de/duenndns/ssl/MTMDecision.java b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MTMDecision.java index 0efe6b515..2b84c3ee5 100644 --- a/libs/MemorizingTrustManager/src/de/duenndns/ssl/MTMDecision.java +++ b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MTMDecision.java @@ -24,10 +24,10 @@ package de.duenndns.ssl; class MTMDecision { - public final static int DECISION_INVALID = 0; - public final static int DECISION_ABORT = 1; - public final static int DECISION_ONCE = 2; - public final static int DECISION_ALWAYS = 3; + public final static int DECISION_INVALID = 0; + public final static int DECISION_ABORT = 1; + public final static int DECISION_ONCE = 2; + public final static int DECISION_ALWAYS = 3; - int state = DECISION_INVALID; + int state = DECISION_INVALID; } diff --git a/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java index 567c2d817..c917c5d08 100644 --- a/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java +++ b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java @@ -36,69 +36,69 @@ import java.util.logging.Level; import java.util.logging.Logger; public class MemorizingActivity extends Activity - implements OnClickListener,OnCancelListener { + implements OnClickListener, OnCancelListener { - private final static Logger LOGGER = Logger.getLogger(MemorizingActivity.class.getName()); + private final static Logger LOGGER = Logger.getLogger(MemorizingActivity.class.getName()); - int decisionId; + int decisionId; - AlertDialog dialog; - - @Override - public void onCreate(Bundle savedInstanceState) { - LOGGER.log(Level.FINE, "onCreate"); - super.onCreate(savedInstanceState); - } + AlertDialog dialog; - @Override - public void onResume() { - super.onResume(); - Intent i = getIntent(); - decisionId = i.getIntExtra(MemorizingTrustManager.DECISION_INTENT_ID, MTMDecision.DECISION_INVALID); - int titleId = i.getIntExtra(MemorizingTrustManager.DECISION_TITLE_ID, R.string.mtm_accept_cert); - String cert = i.getStringExtra(MemorizingTrustManager.DECISION_INTENT_CERT); - LOGGER.log(Level.FINE, "onResume with " + i.getExtras() + " decId=" + decisionId + " data: " + i.getData()); - dialog = new AlertDialog.Builder(this).setTitle(titleId) - .setMessage(cert) - .setPositiveButton(R.string.mtm_decision_always, this) - .setNeutralButton(R.string.mtm_decision_once, this) - .setNegativeButton(R.string.mtm_decision_abort, this) - .setOnCancelListener(this) - .create(); - dialog.show(); - } + @Override + public void onCreate(Bundle savedInstanceState) { + LOGGER.log(Level.FINE, "onCreate"); + super.onCreate(savedInstanceState); + } - @Override - protected void onPause() { - if (dialog.isShowing()) - dialog.dismiss(); - super.onPause(); - } + @Override + public void onResume() { + super.onResume(); + Intent i = getIntent(); + decisionId = i.getIntExtra(MemorizingTrustManager.DECISION_INTENT_ID, MTMDecision.DECISION_INVALID); + int titleId = i.getIntExtra(MemorizingTrustManager.DECISION_TITLE_ID, R.string.mtm_accept_cert); + String cert = i.getStringExtra(MemorizingTrustManager.DECISION_INTENT_CERT); + LOGGER.log(Level.FINE, "onResume with " + i.getExtras() + " decId=" + decisionId + " data: " + i.getData()); + dialog = new AlertDialog.Builder(this).setTitle(titleId) + .setMessage(cert) + .setPositiveButton(R.string.mtm_decision_always, this) + .setNeutralButton(R.string.mtm_decision_once, this) + .setNegativeButton(R.string.mtm_decision_abort, this) + .setOnCancelListener(this) + .create(); + dialog.show(); + } - void sendDecision(int decision) { - LOGGER.log(Level.FINE, "Sending decision: " + decision); - MemorizingTrustManager.interactResult(decisionId, decision); - finish(); - } + @Override + protected void onPause() { + if (dialog.isShowing()) + dialog.dismiss(); + super.onPause(); + } - // react on AlertDialog button press - public void onClick(DialogInterface dialog, int btnId) { - int decision; - dialog.dismiss(); - switch (btnId) { - case DialogInterface.BUTTON_POSITIVE: - decision = MTMDecision.DECISION_ALWAYS; - break; - case DialogInterface.BUTTON_NEUTRAL: - decision = MTMDecision.DECISION_ONCE; - break; - default: - decision = MTMDecision.DECISION_ABORT; - } - sendDecision(decision); - } + void sendDecision(int decision) { + LOGGER.log(Level.FINE, "Sending decision: " + decision); + MemorizingTrustManager.interactResult(decisionId, decision); + finish(); + } - public void onCancel(DialogInterface dialog) { - sendDecision(MTMDecision.DECISION_ABORT); - } + // react on AlertDialog button press + public void onClick(DialogInterface dialog, int btnId) { + int decision; + dialog.dismiss(); + switch (btnId) { + case DialogInterface.BUTTON_POSITIVE: + decision = MTMDecision.DECISION_ALWAYS; + break; + case DialogInterface.BUTTON_NEUTRAL: + decision = MTMDecision.DECISION_ONCE; + break; + default: + decision = MTMDecision.DECISION_ABORT; + } + sendDecision(decision); + } + + public void onCancel(DialogInterface dialog) { + sendDecision(MTMDecision.DECISION_ABORT); + } } diff --git a/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingTrustManager.java b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingTrustManager.java index d1a7e341a..d2fc75db8 100644 --- a/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingTrustManager.java +++ b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingTrustManager.java @@ -73,667 +73,666 @@ import javax.net.ssl.X509TrustManager; * opening sockets! */ public class MemorizingTrustManager implements X509TrustManager { - final static String DECISION_INTENT = "de.duenndns.ssl.DECISION"; - final static String DECISION_INTENT_ID = DECISION_INTENT + ".decisionId"; - final static String DECISION_INTENT_CERT = DECISION_INTENT + ".cert"; - final static String DECISION_INTENT_CHOICE = DECISION_INTENT + ".decisionChoice"; - - private final static Logger LOGGER = Logger.getLogger(MemorizingTrustManager.class.getName()); - final static String DECISION_TITLE_ID = DECISION_INTENT + ".titleId"; - private final static int NOTIFICATION_ID = 100509; - - final static String NO_TRUST_ANCHOR = "Trust anchor for certification path not found."; - - static String KEYSTORE_DIR = "KeyStore"; - static String KEYSTORE_FILE = "KeyStore.bks"; - - Context master; - Activity foregroundAct; - NotificationManager notificationManager; - private static int decisionId = 0; - private static SparseArray<MTMDecision> openDecisions = new SparseArray<MTMDecision>(); - - Handler masterHandler; - private File keyStoreFile; - private KeyStore appKeyStore; - private X509TrustManager defaultTrustManager; - private X509TrustManager appTrustManager; - - /** Creates an instance of the MemorizingTrustManager class that falls back to a custom TrustManager. - * - * You need to supply the application context. This has to be one of: - * - Application - * - Activity - * - Service - * - * The context is used for file management, to display the dialog / - * notification and for obtaining translated strings. - * - * @param m Context for the application. - * @param defaultTrustManager Delegate trust management to this TM. If null, the user must accept every certificate. - */ - public MemorizingTrustManager(Context m, X509TrustManager defaultTrustManager) { - init(m); - this.appTrustManager = getTrustManager(appKeyStore); - this.defaultTrustManager = defaultTrustManager; - } - - /** Creates an instance of the MemorizingTrustManager class using the system X509TrustManager. - * - * You need to supply the application context. This has to be one of: - * - Application - * - Activity - * - Service - * - * The context is used for file management, to display the dialog / - * notification and for obtaining translated strings. - * - * @param m Context for the application. - */ - public MemorizingTrustManager(Context m) { - init(m); - this.appTrustManager = getTrustManager(appKeyStore); - this.defaultTrustManager = getTrustManager(null); - } - - void init(Context m) { - master = m; - masterHandler = new Handler(m.getMainLooper()); - notificationManager = (NotificationManager)master.getSystemService(Context.NOTIFICATION_SERVICE); - - Application app; - if (m instanceof Application) { - app = (Application)m; - } else if (m instanceof Service) { - app = ((Service)m).getApplication(); - } else if (m instanceof Activity) { - app = ((Activity)m).getApplication(); - } else throw new ClassCastException("MemorizingTrustManager context must be either Activity or Service!"); - - File dir = app.getDir(KEYSTORE_DIR, Context.MODE_PRIVATE); - keyStoreFile = new File(dir + File.separator + KEYSTORE_FILE); - - appKeyStore = loadAppKeyStore(); - } - - - /** - * Returns a X509TrustManager list containing a new instance of - * TrustManagerFactory. - * - * This function is meant for convenience only. You can use it - * as follows to integrate TrustManagerFactory for HTTPS sockets: - * - * <pre> - * SSLContext sc = SSLContext.getInstance("TLS"); - * sc.init(null, MemorizingTrustManager.getInstanceList(this), - * new java.security.SecureRandom()); - * HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - * </pre> - * @param c Activity or Service to show the Dialog / Notification - */ - public static X509TrustManager[] getInstanceList(Context c) { - return new X509TrustManager[] { new MemorizingTrustManager(c) }; - } - - /** - * Binds an Activity to the MTM for displaying the query dialog. - * - * This is useful if your connection is run from a service that is - * triggered by user interaction -- in such cases the activity is - * visible and the user tends to ignore the service notification. - * - * You should never have a hidden activity bound to MTM! Use this - * function in onResume() and @see unbindDisplayActivity in onPause(). - * - * @param act Activity to be bound - */ - public void bindDisplayActivity(Activity act) { - foregroundAct = act; - } - - /** - * Removes an Activity from the MTM display stack. - * - * Always call this function when the Activity added with - * {@link #bindDisplayActivity(Activity)} is hidden. - * - * @param act Activity to be unbound - */ - public void unbindDisplayActivity(Activity act) { - // do not remove if it was overridden by a different activity - if (foregroundAct == act) - foregroundAct = null; - } - - /** - * Changes the path for the KeyStore file. - * - * The actual filename relative to the app's directory will be - * <code>app_<i>dirname</i>/<i>filename</i></code>. - * - * @param dirname directory to store the KeyStore. - * @param filename file name for the KeyStore. - */ - public static void setKeyStoreFile(String dirname, String filename) { - KEYSTORE_DIR = dirname; - KEYSTORE_FILE = filename; - } - - /** - * Get a list of all certificate aliases stored in MTM. - * - * @return an {@link Enumeration} of all certificates - */ - public Enumeration<String> getCertificates() { - try { - return appKeyStore.aliases(); - } catch (KeyStoreException e) { - // this should never happen, however... - throw new RuntimeException(e); - } - } - - /** - * Get a certificate for a given alias. - * - * @param alias the certificate's alias as returned by {@link #getCertificates()}. - * - * @return the certificate associated with the alias or <tt>null</tt> if none found. - */ - public Certificate getCertificate(String alias) { - try { - return appKeyStore.getCertificate(alias); - } catch (KeyStoreException e) { - // this should never happen, however... - throw new RuntimeException(e); - } - } - - /** - * Removes the given certificate from MTMs key store. - * - * <p> - * <b>WARNING</b>: this does not immediately invalidate the certificate. It is - * well possible that (a) data is transmitted over still existing connections or - * (b) new connections are created using TLS renegotiation, without a new cert - * check. - * </p> - * @param alias the certificate's alias as returned by {@link #getCertificates()}. - * - * @throws KeyStoreException if the certificate could not be deleted. - */ - public void deleteCertificate(String alias) throws KeyStoreException { - appKeyStore.deleteEntry(alias); - keyStoreUpdated(); - } - - /** - * Creates a new hostname verifier supporting user interaction. - * - * <p>This method creates a new {@link HostnameVerifier} that is bound to - * the given instance of {@link MemorizingTrustManager}, and leverages an - * existing {@link HostnameVerifier}. The returned verifier performs the - * following steps, returning as soon as one of them succeeds: - * </p> - * <ol> - * <li>Success, if the wrapped defaultVerifier accepts the certificate.</li> - * <li>Success, if the server certificate is stored in the keystore under the given hostname.</li> - * <li>Ask the user and return accordingly.</li> - * <li>Failure on exception.</li> - * </ol> - * - * @param defaultVerifier the {@link HostnameVerifier} that should perform the actual check - * @return a new hostname verifier using the MTM's key store - * - * @throws IllegalArgumentException if the defaultVerifier parameter is null - */ - public HostnameVerifier wrapHostnameVerifier(final HostnameVerifier defaultVerifier) { - if (defaultVerifier == null) - throw new IllegalArgumentException("The default verifier may not be null"); - - return new MemorizingHostnameVerifier(defaultVerifier); - } - - public HostnameVerifier wrapHostnameVerifierNonInteractive(final HostnameVerifier defaultVerifier) { - if (defaultVerifier == null) - throw new IllegalArgumentException("The default verifier may not be null"); - - return new NonInteractiveMemorizingHostnameVerifier(defaultVerifier); - } - - X509TrustManager getTrustManager(KeyStore ks) { - try { - TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); - tmf.init(ks); - for (TrustManager t : tmf.getTrustManagers()) { - if (t instanceof X509TrustManager) { - return (X509TrustManager)t; - } - } - } catch (Exception e) { - // Here, we are covering up errors. It might be more useful - // however to throw them out of the constructor so the - // embedding app knows something went wrong. - LOGGER.log(Level.SEVERE, "getTrustManager(" + ks + ")", e); - } - return null; - } - - KeyStore loadAppKeyStore() { - KeyStore ks; - try { - ks = KeyStore.getInstance(KeyStore.getDefaultType()); - } catch (KeyStoreException e) { - LOGGER.log(Level.SEVERE, "getAppKeyStore()", e); - return null; - } - try { - ks.load(null, null); - ks.load(new java.io.FileInputStream(keyStoreFile), "MTM".toCharArray()); - } catch (java.io.FileNotFoundException e) { - LOGGER.log(Level.INFO, "getAppKeyStore(" + keyStoreFile + ") - file does not exist"); - } catch (Exception e) { - LOGGER.log(Level.SEVERE, "getAppKeyStore(" + keyStoreFile + ")", e); - } - return ks; - } - - void storeCert(String alias, Certificate cert) { - try { - appKeyStore.setCertificateEntry(alias, cert); - } catch (KeyStoreException e) { - LOGGER.log(Level.SEVERE, "storeCert(" + cert + ")", e); - return; - } - keyStoreUpdated(); - } - - void storeCert(X509Certificate cert) { - storeCert(cert.getSubjectDN().toString(), cert); - } - - void keyStoreUpdated() { - // reload appTrustManager - appTrustManager = getTrustManager(appKeyStore); - - // store KeyStore to file - java.io.FileOutputStream fos = null; - try { - fos = new java.io.FileOutputStream(keyStoreFile); - appKeyStore.store(fos, "MTM".toCharArray()); - } catch (Exception e) { - LOGGER.log(Level.SEVERE, "storeCert(" + keyStoreFile + ")", e); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, "storeCert(" + keyStoreFile + ")", e); - } - } - } - } - - // if the certificate is stored in the app key store, it is considered "known" - private boolean isCertKnown(X509Certificate cert) { - try { - return appKeyStore.getCertificateAlias(cert) != null; - } catch (KeyStoreException e) { - return false; - } - } - - private boolean isExpiredException(Throwable e) { - do { - if (e instanceof CertificateExpiredException) - return true; - e = e.getCause(); - } while (e != null); - return false; - } - - public void checkCertTrusted(X509Certificate[] chain, String authType, boolean isServer, boolean interactive) - throws CertificateException - { - LOGGER.log(Level.FINE, "checkCertTrusted(" + chain + ", " + authType + ", " + isServer + ")"); - try { - LOGGER.log(Level.FINE, "checkCertTrusted: trying appTrustManager"); - if (isServer) - appTrustManager.checkServerTrusted(chain, authType); - else - appTrustManager.checkClientTrusted(chain, authType); - } catch (CertificateException ae) { - LOGGER.log(Level.FINER, "checkCertTrusted: appTrustManager failed", ae); - // if the cert is stored in our appTrustManager, we ignore expiredness - if (isExpiredException(ae)) { - LOGGER.log(Level.INFO, "checkCertTrusted: accepting expired certificate from keystore"); - return; - } - if (isCertKnown(chain[0])) { - LOGGER.log(Level.INFO, "checkCertTrusted: accepting cert already stored in keystore"); - return; - } - try { - if (defaultTrustManager == null) - throw ae; - LOGGER.log(Level.FINE, "checkCertTrusted: trying defaultTrustManager"); - if (isServer) - defaultTrustManager.checkServerTrusted(chain, authType); - else - defaultTrustManager.checkClientTrusted(chain, authType); - } catch (CertificateException e) { - e.printStackTrace(); - if (interactive) { - interactCert(chain, authType, e); - } else { - throw e; - } - } - } - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) - throws CertificateException - { - checkCertTrusted(chain, authType, false,true); - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) - throws CertificateException - { - checkCertTrusted(chain, authType, true,true); - } - - public X509Certificate[] getAcceptedIssuers() - { - LOGGER.log(Level.FINE, "getAcceptedIssuers()"); - return defaultTrustManager.getAcceptedIssuers(); - } - - private int createDecisionId(MTMDecision d) { - int myId; - synchronized(openDecisions) { - myId = decisionId; - openDecisions.put(myId, d); - decisionId += 1; - } - return myId; - } - - private static String hexString(byte[] data) { - StringBuffer si = new StringBuffer(); - for (int i = 0; i < data.length; i++) { - si.append(String.format("%02x", data[i])); - if (i < data.length - 1) - si.append(":"); - } - return si.toString(); - } - - private static String certHash(final X509Certificate cert, String digest) { - try { - MessageDigest md = MessageDigest.getInstance(digest); - md.update(cert.getEncoded()); - return hexString(md.digest()); - } catch (java.security.cert.CertificateEncodingException e) { - return e.getMessage(); - } catch (java.security.NoSuchAlgorithmException e) { - return e.getMessage(); - } - } - - private void certDetails(StringBuffer si, X509Certificate c) { - SimpleDateFormat validityDateFormater = new SimpleDateFormat("yyyy-MM-dd"); - si.append("\n"); - si.append(c.getSubjectDN().toString()); - si.append("\n"); - si.append(validityDateFormater.format(c.getNotBefore())); - si.append(" - "); - si.append(validityDateFormater.format(c.getNotAfter())); - si.append("\nSHA-256: "); - si.append(certHash(c, "SHA-256")); - si.append("\nSHA-1: "); - si.append(certHash(c, "SHA-1")); - si.append("\nSigned by: "); - si.append(c.getIssuerDN().toString()); - si.append("\n"); - } - - private String certChainMessage(final X509Certificate[] chain, CertificateException cause) { - Throwable e = cause; - LOGGER.log(Level.FINE, "certChainMessage for " + e); - StringBuffer si = new StringBuffer(); - if (e.getCause() != null) { - e = e.getCause(); - // HACK: there is no sane way to check if the error is a "trust anchor - // not found", so we use string comparison. - if (NO_TRUST_ANCHOR.equals(e.getMessage())) { - si.append(master.getString(R.string.mtm_trust_anchor)); - } else - si.append(e.getLocalizedMessage()); - si.append("\n"); - } - si.append("\n"); - si.append(master.getString(R.string.mtm_connect_anyway)); - si.append("\n\n"); - si.append(master.getString(R.string.mtm_cert_details)); - for (X509Certificate c : chain) { - certDetails(si, c); - } - return si.toString(); - } - - private String hostNameMessage(X509Certificate cert, String hostname) { - StringBuffer si = new StringBuffer(); - - si.append(master.getString(R.string.mtm_hostname_mismatch, hostname)); - si.append("\n\n"); - try { - Collection<List<?>> sans = cert.getSubjectAlternativeNames(); - if (sans == null) { - si.append(cert.getSubjectDN()); - si.append("\n"); - } else for (List<?> altName : sans) { - Object name = altName.get(1); - if (name instanceof String) { - si.append("["); - si.append((Integer)altName.get(0)); - si.append("] "); - si.append(name); - si.append("\n"); - } - } - } catch (CertificateParsingException e) { - e.printStackTrace(); - si.append("<Parsing error: "); - si.append(e.getLocalizedMessage()); - si.append(">\n"); - } - si.append("\n"); - si.append(master.getString(R.string.mtm_connect_anyway)); - si.append("\n\n"); - si.append(master.getString(R.string.mtm_cert_details)); - certDetails(si, cert); - return si.toString(); - } - - // We can use Notification.Builder once MTM's minSDK is >= 11 - @SuppressWarnings("deprecation") - void startActivityNotification(Intent intent, int decisionId, String certName) { - Notification n = new Notification(android.R.drawable.ic_lock_lock, - master.getString(R.string.mtm_notification), - System.currentTimeMillis()); - PendingIntent call = PendingIntent.getActivity(master, 0, intent, 0); - n.setLatestEventInfo(master.getApplicationContext(), - master.getString(R.string.mtm_notification), - certName, call); - n.flags |= Notification.FLAG_AUTO_CANCEL; - - notificationManager.notify(NOTIFICATION_ID + decisionId, n); - } - - /** - * Returns the top-most entry of the activity stack. - * - * @return the Context of the currently bound UI or the master context if none is bound - */ - Context getUI() { - return (foregroundAct != null) ? foregroundAct : master; - } - - int interact(final String message, final int titleId) { - /* prepare the MTMDecision blocker object */ - MTMDecision choice = new MTMDecision(); - final int myId = createDecisionId(choice); - - masterHandler.post(new Runnable() { - public void run() { - Intent ni = new Intent(master, MemorizingActivity.class); - ni.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - ni.setData(Uri.parse(MemorizingTrustManager.class.getName() + "/" + myId)); - ni.putExtra(DECISION_INTENT_ID, myId); - ni.putExtra(DECISION_INTENT_CERT, message); - ni.putExtra(DECISION_TITLE_ID, titleId); - - // we try to directly start the activity and fall back to - // making a notification - try { - getUI().startActivity(ni); - } catch (Exception e) { - LOGGER.log(Level.FINE, "startActivity(MemorizingActivity)", e); - startActivityNotification(ni, myId, message); - } - } - }); - - LOGGER.log(Level.FINE, "openDecisions: " + openDecisions + ", waiting on " + myId); - try { - synchronized(choice) { choice.wait(); } - } catch (InterruptedException e) { - LOGGER.log(Level.FINER, "InterruptedException", e); - } - LOGGER.log(Level.FINE, "finished wait on " + myId + ": " + choice.state); - return choice.state; - } - - void interactCert(final X509Certificate[] chain, String authType, CertificateException cause) - throws CertificateException - { - switch (interact(certChainMessage(chain, cause), R.string.mtm_accept_cert)) { - case MTMDecision.DECISION_ALWAYS: - storeCert(chain[0]); // only store the server cert, not the whole chain - case MTMDecision.DECISION_ONCE: - break; - default: - throw (cause); - } - } - - boolean interactHostname(X509Certificate cert, String hostname) - { - switch (interact(hostNameMessage(cert, hostname), R.string.mtm_accept_servername)) { - case MTMDecision.DECISION_ALWAYS: - storeCert(hostname, cert); - case MTMDecision.DECISION_ONCE: - return true; - default: - return false; - } - } - - protected static void interactResult(int decisionId, int choice) { - MTMDecision d; - synchronized(openDecisions) { - d = openDecisions.get(decisionId); - openDecisions.remove(decisionId); - } - if (d == null) { - LOGGER.log(Level.SEVERE, "interactResult: aborting due to stale decision reference!"); - return; - } - synchronized(d) { - d.state = choice; - d.notify(); - } - } - - class MemorizingHostnameVerifier implements HostnameVerifier { - private HostnameVerifier defaultVerifier; - - public MemorizingHostnameVerifier(HostnameVerifier wrapped) { - defaultVerifier = wrapped; - } - - protected boolean verify(String hostname, SSLSession session, boolean interactive) { - LOGGER.log(Level.FINE, "hostname verifier for " + hostname + ", trying default verifier first"); - // if the default verifier accepts the hostname, we are done - if (defaultVerifier.verify(hostname, session)) { - LOGGER.log(Level.FINE, "default verifier accepted " + hostname); - return true; - } - // otherwise, we check if the hostname is an alias for this cert in our keystore - try { - X509Certificate cert = (X509Certificate)session.getPeerCertificates()[0]; - //Log.d(TAG, "cert: " + cert); - if (cert.equals(appKeyStore.getCertificate(hostname.toLowerCase(Locale.US)))) { - LOGGER.log(Level.FINE, "certificate for " + hostname + " is in our keystore. accepting."); - return true; - } else { - LOGGER.log(Level.FINE, "server " + hostname + " provided wrong certificate, asking user."); - if (interactive) { - return interactHostname(cert, hostname); - } else { - return false; - } - } - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - - @Override - public boolean verify(String hostname, SSLSession session) { - return verify(hostname, session, true); - } - } - - class NonInteractiveMemorizingHostnameVerifier extends MemorizingHostnameVerifier { - - public NonInteractiveMemorizingHostnameVerifier(HostnameVerifier wrapped) { - super(wrapped); - } - @Override - public boolean verify(String hostname, SSLSession session) { - return verify(hostname, session, false); - } - - - } - - public X509TrustManager getNonInteractive() { - return new NonInteractiveMemorizingTrustManager(); - } - - private class NonInteractiveMemorizingTrustManager implements X509TrustManager { - - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) - throws CertificateException { - MemorizingTrustManager.this.checkCertTrusted(chain, authType, false, false); - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) - throws CertificateException { - MemorizingTrustManager.this.checkCertTrusted(chain, authType, true, false); - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return MemorizingTrustManager.this.getAcceptedIssuers(); - } - - } + final static String DECISION_INTENT = "de.duenndns.ssl.DECISION"; + final static String DECISION_INTENT_ID = DECISION_INTENT + ".decisionId"; + final static String DECISION_INTENT_CERT = DECISION_INTENT + ".cert"; + final static String DECISION_INTENT_CHOICE = DECISION_INTENT + ".decisionChoice"; + + private final static Logger LOGGER = Logger.getLogger(MemorizingTrustManager.class.getName()); + final static String DECISION_TITLE_ID = DECISION_INTENT + ".titleId"; + private final static int NOTIFICATION_ID = 100509; + + final static String NO_TRUST_ANCHOR = "Trust anchor for certification path not found."; + + static String KEYSTORE_DIR = "KeyStore"; + static String KEYSTORE_FILE = "KeyStore.bks"; + + Context master; + Activity foregroundAct; + NotificationManager notificationManager; + private static int decisionId = 0; + private static SparseArray<MTMDecision> openDecisions = new SparseArray<MTMDecision>(); + + Handler masterHandler; + private File keyStoreFile; + private KeyStore appKeyStore; + private X509TrustManager defaultTrustManager; + private X509TrustManager appTrustManager; + + /** + * Creates an instance of the MemorizingTrustManager class that falls back to a custom TrustManager. + * <p> + * You need to supply the application context. This has to be one of: + * - Application + * - Activity + * - Service + * <p> + * The context is used for file management, to display the dialog / + * notification and for obtaining translated strings. + * + * @param m Context for the application. + * @param defaultTrustManager Delegate trust management to this TM. If null, the user must accept every certificate. + */ + public MemorizingTrustManager(Context m, X509TrustManager defaultTrustManager) { + init(m); + this.appTrustManager = getTrustManager(appKeyStore); + this.defaultTrustManager = defaultTrustManager; + } + + /** + * Creates an instance of the MemorizingTrustManager class using the system X509TrustManager. + * <p> + * You need to supply the application context. This has to be one of: + * - Application + * - Activity + * - Service + * <p> + * The context is used for file management, to display the dialog / + * notification and for obtaining translated strings. + * + * @param m Context for the application. + */ + public MemorizingTrustManager(Context m) { + init(m); + this.appTrustManager = getTrustManager(appKeyStore); + this.defaultTrustManager = getTrustManager(null); + } + + void init(Context m) { + master = m; + masterHandler = new Handler(m.getMainLooper()); + notificationManager = (NotificationManager) master.getSystemService(Context.NOTIFICATION_SERVICE); + + Application app; + if (m instanceof Application) { + app = (Application) m; + } else if (m instanceof Service) { + app = ((Service) m).getApplication(); + } else if (m instanceof Activity) { + app = ((Activity) m).getApplication(); + } else + throw new ClassCastException("MemorizingTrustManager context must be either Activity or Service!"); + + File dir = app.getDir(KEYSTORE_DIR, Context.MODE_PRIVATE); + keyStoreFile = new File(dir + File.separator + KEYSTORE_FILE); + + appKeyStore = loadAppKeyStore(); + } + + + /** + * Returns a X509TrustManager list containing a new instance of + * TrustManagerFactory. + * <p> + * This function is meant for convenience only. You can use it + * as follows to integrate TrustManagerFactory for HTTPS sockets: + * <p> + * <pre> + * SSLContext sc = SSLContext.getInstance("TLS"); + * sc.init(null, MemorizingTrustManager.getInstanceList(this), + * new java.security.SecureRandom()); + * HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + * </pre> + * + * @param c Activity or Service to show the Dialog / Notification + */ + public static X509TrustManager[] getInstanceList(Context c) { + return new X509TrustManager[]{new MemorizingTrustManager(c)}; + } + + /** + * Binds an Activity to the MTM for displaying the query dialog. + * <p> + * This is useful if your connection is run from a service that is + * triggered by user interaction -- in such cases the activity is + * visible and the user tends to ignore the service notification. + * <p> + * You should never have a hidden activity bound to MTM! Use this + * function in onResume() and @see unbindDisplayActivity in onPause(). + * + * @param act Activity to be bound + */ + public void bindDisplayActivity(Activity act) { + foregroundAct = act; + } + + /** + * Removes an Activity from the MTM display stack. + * <p> + * Always call this function when the Activity added with + * {@link #bindDisplayActivity(Activity)} is hidden. + * + * @param act Activity to be unbound + */ + public void unbindDisplayActivity(Activity act) { + // do not remove if it was overridden by a different activity + if (foregroundAct == act) + foregroundAct = null; + } + + /** + * Changes the path for the KeyStore file. + * <p> + * The actual filename relative to the app's directory will be + * <code>app_<i>dirname</i>/<i>filename</i></code>. + * + * @param dirname directory to store the KeyStore. + * @param filename file name for the KeyStore. + */ + public static void setKeyStoreFile(String dirname, String filename) { + KEYSTORE_DIR = dirname; + KEYSTORE_FILE = filename; + } + + /** + * Get a list of all certificate aliases stored in MTM. + * + * @return an {@link Enumeration} of all certificates + */ + public Enumeration<String> getCertificates() { + try { + return appKeyStore.aliases(); + } catch (KeyStoreException e) { + // this should never happen, however... + throw new RuntimeException(e); + } + } + + /** + * Get a certificate for a given alias. + * + * @param alias the certificate's alias as returned by {@link #getCertificates()}. + * @return the certificate associated with the alias or <tt>null</tt> if none found. + */ + public Certificate getCertificate(String alias) { + try { + return appKeyStore.getCertificate(alias); + } catch (KeyStoreException e) { + // this should never happen, however... + throw new RuntimeException(e); + } + } + + /** + * Removes the given certificate from MTMs key store. + * <p> + * <p> + * <b>WARNING</b>: this does not immediately invalidate the certificate. It is + * well possible that (a) data is transmitted over still existing connections or + * (b) new connections are created using TLS renegotiation, without a new cert + * check. + * </p> + * + * @param alias the certificate's alias as returned by {@link #getCertificates()}. + * @throws KeyStoreException if the certificate could not be deleted. + */ + public void deleteCertificate(String alias) throws KeyStoreException { + appKeyStore.deleteEntry(alias); + keyStoreUpdated(); + } + + /** + * Creates a new hostname verifier supporting user interaction. + * <p> + * <p>This method creates a new {@link HostnameVerifier} that is bound to + * the given instance of {@link MemorizingTrustManager}, and leverages an + * existing {@link HostnameVerifier}. The returned verifier performs the + * following steps, returning as soon as one of them succeeds: + * </p> + * <ol> + * <li>Success, if the wrapped defaultVerifier accepts the certificate.</li> + * <li>Success, if the server certificate is stored in the keystore under the given hostname.</li> + * <li>Ask the user and return accordingly.</li> + * <li>Failure on exception.</li> + * </ol> + * + * @param defaultVerifier the {@link HostnameVerifier} that should perform the actual check + * @return a new hostname verifier using the MTM's key store + * @throws IllegalArgumentException if the defaultVerifier parameter is null + */ + public HostnameVerifier wrapHostnameVerifier(final HostnameVerifier defaultVerifier) { + if (defaultVerifier == null) + throw new IllegalArgumentException("The default verifier may not be null"); + + return new MemorizingHostnameVerifier(defaultVerifier); + } + + public HostnameVerifier wrapHostnameVerifierNonInteractive(final HostnameVerifier defaultVerifier) { + if (defaultVerifier == null) + throw new IllegalArgumentException("The default verifier may not be null"); + + return new NonInteractiveMemorizingHostnameVerifier(defaultVerifier); + } + + X509TrustManager getTrustManager(KeyStore ks) { + try { + TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); + tmf.init(ks); + for (TrustManager t : tmf.getTrustManagers()) { + if (t instanceof X509TrustManager) { + return (X509TrustManager) t; + } + } + } catch (Exception e) { + // Here, we are covering up errors. It might be more useful + // however to throw them out of the constructor so the + // embedding app knows something went wrong. + LOGGER.log(Level.SEVERE, "getTrustManager(" + ks + ")", e); + } + return null; + } + + KeyStore loadAppKeyStore() { + KeyStore ks; + try { + ks = KeyStore.getInstance(KeyStore.getDefaultType()); + } catch (KeyStoreException e) { + LOGGER.log(Level.SEVERE, "getAppKeyStore()", e); + return null; + } + try { + ks.load(null, null); + ks.load(new java.io.FileInputStream(keyStoreFile), "MTM".toCharArray()); + } catch (java.io.FileNotFoundException e) { + LOGGER.log(Level.INFO, "getAppKeyStore(" + keyStoreFile + ") - file does not exist"); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "getAppKeyStore(" + keyStoreFile + ")", e); + } + return ks; + } + + void storeCert(String alias, Certificate cert) { + try { + appKeyStore.setCertificateEntry(alias, cert); + } catch (KeyStoreException e) { + LOGGER.log(Level.SEVERE, "storeCert(" + cert + ")", e); + return; + } + keyStoreUpdated(); + } + + void storeCert(X509Certificate cert) { + storeCert(cert.getSubjectDN().toString(), cert); + } + + void keyStoreUpdated() { + // reload appTrustManager + appTrustManager = getTrustManager(appKeyStore); + + // store KeyStore to file + java.io.FileOutputStream fos = null; + try { + fos = new java.io.FileOutputStream(keyStoreFile); + appKeyStore.store(fos, "MTM".toCharArray()); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "storeCert(" + keyStoreFile + ")", e); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, "storeCert(" + keyStoreFile + ")", e); + } + } + } + } + + // if the certificate is stored in the app key store, it is considered "known" + private boolean isCertKnown(X509Certificate cert) { + try { + return appKeyStore.getCertificateAlias(cert) != null; + } catch (KeyStoreException e) { + return false; + } + } + + private boolean isExpiredException(Throwable e) { + do { + if (e instanceof CertificateExpiredException) + return true; + e = e.getCause(); + } while (e != null); + return false; + } + + public void checkCertTrusted(X509Certificate[] chain, String authType, boolean isServer, boolean interactive) + throws CertificateException { + LOGGER.log(Level.FINE, "checkCertTrusted(" + chain + ", " + authType + ", " + isServer + ")"); + try { + LOGGER.log(Level.FINE, "checkCertTrusted: trying appTrustManager"); + if (isServer) + appTrustManager.checkServerTrusted(chain, authType); + else + appTrustManager.checkClientTrusted(chain, authType); + } catch (CertificateException ae) { + LOGGER.log(Level.FINER, "checkCertTrusted: appTrustManager failed", ae); + // if the cert is stored in our appTrustManager, we ignore expiredness + if (isExpiredException(ae)) { + LOGGER.log(Level.INFO, "checkCertTrusted: accepting expired certificate from keystore"); + return; + } + if (isCertKnown(chain[0])) { + LOGGER.log(Level.INFO, "checkCertTrusted: accepting cert already stored in keystore"); + return; + } + try { + if (defaultTrustManager == null) + throw ae; + LOGGER.log(Level.FINE, "checkCertTrusted: trying defaultTrustManager"); + if (isServer) + defaultTrustManager.checkServerTrusted(chain, authType); + else + defaultTrustManager.checkClientTrusted(chain, authType); + } catch (CertificateException e) { + e.printStackTrace(); + if (interactive) { + interactCert(chain, authType, e); + } else { + throw e; + } + } + } + } + + public void checkClientTrusted(X509Certificate[] chain, String authType) + throws CertificateException { + checkCertTrusted(chain, authType, false, true); + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) + throws CertificateException { + checkCertTrusted(chain, authType, true, true); + } + + public X509Certificate[] getAcceptedIssuers() { + LOGGER.log(Level.FINE, "getAcceptedIssuers()"); + return defaultTrustManager.getAcceptedIssuers(); + } + + private int createDecisionId(MTMDecision d) { + int myId; + synchronized (openDecisions) { + myId = decisionId; + openDecisions.put(myId, d); + decisionId += 1; + } + return myId; + } + + private static String hexString(byte[] data) { + StringBuffer si = new StringBuffer(); + for (int i = 0; i < data.length; i++) { + si.append(String.format("%02x", data[i])); + if (i < data.length - 1) + si.append(":"); + } + return si.toString(); + } + + private static String certHash(final X509Certificate cert, String digest) { + try { + MessageDigest md = MessageDigest.getInstance(digest); + md.update(cert.getEncoded()); + return hexString(md.digest()); + } catch (java.security.cert.CertificateEncodingException e) { + return e.getMessage(); + } catch (java.security.NoSuchAlgorithmException e) { + return e.getMessage(); + } + } + + private void certDetails(StringBuffer si, X509Certificate c) { + SimpleDateFormat validityDateFormater = new SimpleDateFormat("yyyy-MM-dd"); + si.append("\n"); + si.append(c.getSubjectDN().toString()); + si.append("\n"); + si.append(validityDateFormater.format(c.getNotBefore())); + si.append(" - "); + si.append(validityDateFormater.format(c.getNotAfter())); + si.append("\nSHA-256: "); + si.append(certHash(c, "SHA-256")); + si.append("\nSHA-1: "); + si.append(certHash(c, "SHA-1")); + si.append("\nSigned by: "); + si.append(c.getIssuerDN().toString()); + si.append("\n"); + } + + private String certChainMessage(final X509Certificate[] chain, CertificateException cause) { + Throwable e = cause; + LOGGER.log(Level.FINE, "certChainMessage for " + e); + StringBuffer si = new StringBuffer(); + if (e.getCause() != null) { + e = e.getCause(); + // HACK: there is no sane way to check if the error is a "trust anchor + // not found", so we use string comparison. + if (NO_TRUST_ANCHOR.equals(e.getMessage())) { + si.append(master.getString(R.string.mtm_trust_anchor)); + } else + si.append(e.getLocalizedMessage()); + si.append("\n"); + } + si.append("\n"); + si.append(master.getString(R.string.mtm_connect_anyway)); + si.append("\n\n"); + si.append(master.getString(R.string.mtm_cert_details)); + for (X509Certificate c : chain) { + certDetails(si, c); + } + return si.toString(); + } + + private String hostNameMessage(X509Certificate cert, String hostname) { + StringBuffer si = new StringBuffer(); + + si.append(master.getString(R.string.mtm_hostname_mismatch, hostname)); + si.append("\n\n"); + try { + Collection<List<?>> sans = cert.getSubjectAlternativeNames(); + if (sans == null) { + si.append(cert.getSubjectDN()); + si.append("\n"); + } else for (List<?> altName : sans) { + Object name = altName.get(1); + if (name instanceof String) { + si.append("["); + si.append((Integer) altName.get(0)); + si.append("] "); + si.append(name); + si.append("\n"); + } + } + } catch (CertificateParsingException e) { + e.printStackTrace(); + si.append("<Parsing error: "); + si.append(e.getLocalizedMessage()); + si.append(">\n"); + } + si.append("\n"); + si.append(master.getString(R.string.mtm_connect_anyway)); + si.append("\n\n"); + si.append(master.getString(R.string.mtm_cert_details)); + certDetails(si, cert); + return si.toString(); + } + + // We can use Notification.Builder once MTM's minSDK is >= 11 + @SuppressWarnings("deprecation") + void startActivityNotification(Intent intent, int decisionId, String certName) { + Notification n = new Notification(android.R.drawable.ic_lock_lock, + master.getString(R.string.mtm_notification), + System.currentTimeMillis()); + PendingIntent call = PendingIntent.getActivity(master, 0, intent, 0); + n.setLatestEventInfo(master.getApplicationContext(), + master.getString(R.string.mtm_notification), + certName, call); + n.flags |= Notification.FLAG_AUTO_CANCEL; + + notificationManager.notify(NOTIFICATION_ID + decisionId, n); + } + + /** + * Returns the top-most entry of the activity stack. + * + * @return the Context of the currently bound UI or the master context if none is bound + */ + Context getUI() { + return (foregroundAct != null) ? foregroundAct : master; + } + + int interact(final String message, final int titleId) { + /* prepare the MTMDecision blocker object */ + MTMDecision choice = new MTMDecision(); + final int myId = createDecisionId(choice); + + masterHandler.post(new Runnable() { + public void run() { + Intent ni = new Intent(master, MemorizingActivity.class); + ni.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ni.setData(Uri.parse(MemorizingTrustManager.class.getName() + "/" + myId)); + ni.putExtra(DECISION_INTENT_ID, myId); + ni.putExtra(DECISION_INTENT_CERT, message); + ni.putExtra(DECISION_TITLE_ID, titleId); + + // we try to directly start the activity and fall back to + // making a notification + try { + getUI().startActivity(ni); + } catch (Exception e) { + LOGGER.log(Level.FINE, "startActivity(MemorizingActivity)", e); + startActivityNotification(ni, myId, message); + } + } + }); + + LOGGER.log(Level.FINE, "openDecisions: " + openDecisions + ", waiting on " + myId); + try { + synchronized (choice) { + choice.wait(); + } + } catch (InterruptedException e) { + LOGGER.log(Level.FINER, "InterruptedException", e); + } + LOGGER.log(Level.FINE, "finished wait on " + myId + ": " + choice.state); + return choice.state; + } + + void interactCert(final X509Certificate[] chain, String authType, CertificateException cause) + throws CertificateException { + switch (interact(certChainMessage(chain, cause), R.string.mtm_accept_cert)) { + case MTMDecision.DECISION_ALWAYS: + storeCert(chain[0]); // only store the server cert, not the whole chain + case MTMDecision.DECISION_ONCE: + break; + default: + throw (cause); + } + } + + boolean interactHostname(X509Certificate cert, String hostname) { + switch (interact(hostNameMessage(cert, hostname), R.string.mtm_accept_servername)) { + case MTMDecision.DECISION_ALWAYS: + storeCert(hostname, cert); + case MTMDecision.DECISION_ONCE: + return true; + default: + return false; + } + } + + protected static void interactResult(int decisionId, int choice) { + MTMDecision d; + synchronized (openDecisions) { + d = openDecisions.get(decisionId); + openDecisions.remove(decisionId); + } + if (d == null) { + LOGGER.log(Level.SEVERE, "interactResult: aborting due to stale decision reference!"); + return; + } + synchronized (d) { + d.state = choice; + d.notify(); + } + } + + class MemorizingHostnameVerifier implements HostnameVerifier { + private HostnameVerifier defaultVerifier; + + public MemorizingHostnameVerifier(HostnameVerifier wrapped) { + defaultVerifier = wrapped; + } + + protected boolean verify(String hostname, SSLSession session, boolean interactive) { + LOGGER.log(Level.FINE, "hostname verifier for " + hostname + ", trying default verifier first"); + // if the default verifier accepts the hostname, we are done + if (defaultVerifier.verify(hostname, session)) { + LOGGER.log(Level.FINE, "default verifier accepted " + hostname); + return true; + } + // otherwise, we check if the hostname is an alias for this cert in our keystore + try { + X509Certificate cert = (X509Certificate) session.getPeerCertificates()[0]; + //Log.d(TAG, "cert: " + cert); + if (cert.equals(appKeyStore.getCertificate(hostname.toLowerCase(Locale.US)))) { + LOGGER.log(Level.FINE, "certificate for " + hostname + " is in our keystore. accepting."); + return true; + } else { + LOGGER.log(Level.FINE, "server " + hostname + " provided wrong certificate, asking user."); + if (interactive) { + return interactHostname(cert, hostname); + } else { + return false; + } + } + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + @Override + public boolean verify(String hostname, SSLSession session) { + return verify(hostname, session, true); + } + } + + class NonInteractiveMemorizingHostnameVerifier extends MemorizingHostnameVerifier { + + public NonInteractiveMemorizingHostnameVerifier(HostnameVerifier wrapped) { + super(wrapped); + } + + @Override + public boolean verify(String hostname, SSLSession session) { + return verify(hostname, session, false); + } + + + } + + public X509TrustManager getNonInteractive() { + return new NonInteractiveMemorizingTrustManager(); + } + + private class NonInteractiveMemorizingTrustManager implements X509TrustManager { + + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) + throws CertificateException { + MemorizingTrustManager.this.checkCertTrusted(chain, authType, false, false); + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) + throws CertificateException { + MemorizingTrustManager.this.checkCertTrusted(chain, authType, true, false); + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return MemorizingTrustManager.this.getAcceptedIssuers(); + } + + } } diff --git a/libs/audiowife/build.gradle b/libs/audiowife/build.gradle index 63c2e8e78..15adabe9f 100644 --- a/libs/audiowife/build.gradle +++ b/libs/audiowife/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 + compileSdkVersion 23 buildToolsVersion "23.0.3" - defaultConfig { - minSdkVersion 14 - targetSdkVersion 21 + defaultConfig { + minSdkVersion 14 + targetSdkVersion 21 versionCode 1 versionName "1.0" } diff --git a/libs/audiowife/src/main/AndroidManifest.xml b/libs/audiowife/src/main/AndroidManifest.xml index dad095276..5876c3afe 100644 --- a/libs/audiowife/src/main/AndroidManifest.xml +++ b/libs/audiowife/src/main/AndroidManifest.xml @@ -1,7 +1,8 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="nl.changer.audiowife"> - <application android:allowBackup="true" + <application + android:allowBackup="true" android:label="@string/app_name"> </application> diff --git a/libs/audiowife/src/main/java/nl/changer/audiowife/AudioWife.java b/libs/audiowife/src/main/java/nl/changer/audiowife/AudioWife.java index 26fb08e91..25bf7a003 100644 --- a/libs/audiowife/src/main/java/nl/changer/audiowife/AudioWife.java +++ b/libs/audiowife/src/main/java/nl/changer/audiowife/AudioWife.java @@ -685,6 +685,7 @@ public class AudioWife { mHasDefaultUi = true; return this; } + public void release() { if (mMediaPlayer != null) { diff --git a/libs/audiowife/src/main/res/drawable/gray_border_wo_padding.xml b/libs/audiowife/src/main/res/drawable/gray_border_wo_padding.xml index 409ed7ccd..890aadcbf 100644 --- a/libs/audiowife/src/main/res/drawable/gray_border_wo_padding.xml +++ b/libs/audiowife/src/main/res/drawable/gray_border_wo_padding.xml @@ -1,12 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> -<shape xmlns:android="http://schemas.android.com/apk/res/android" > +<shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- view border color and width --> <stroke android:width="1dp" - android:color="#F2F2F2" > - </stroke> + android:color="#F2F2F2"></stroke> <gradient android:endColor="@android:color/white" diff --git a/libs/audiowife/src/main/res/layout/aw_player.xml b/libs/audiowife/src/main/res/layout/aw_player.xml index 6d2904e31..f3e061381 100644 --- a/libs/audiowife/src/main/res/layout/aw_player.xml +++ b/libs/audiowife/src/main/res/layout/aw_player.xml @@ -27,7 +27,7 @@ android:layout_weight="0.8" android:paddingBottom="5dp" android:paddingRight="10dp" - android:paddingTop="5dp" > + android:paddingTop="5dp"> <SeekBar android:id="@+id/media_seekbar" diff --git a/libs/emojicon/AndroidManifest.xml b/libs/emojicon/AndroidManifest.xml index a07b8e21b..135e6fec5 100644 --- a/libs/emojicon/AndroidManifest.xml +++ b/libs/emojicon/AndroidManifest.xml @@ -1,9 +1,12 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="github.ankushsachdeva.emojicon"> - <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/> + <uses-sdk + android:minSdkVersion="8" + android:targetSdkVersion="19" /> - <application android:allowBackup="true" + <application + android:allowBackup="true" android:label="@string/app_name" android:icon="@drawable/ic_launcher"> diff --git a/libs/emojicon/lint.xml b/libs/emojicon/lint.xml index 8423c0ef9..c70207fba 100644 --- a/libs/emojicon/lint.xml +++ b/libs/emojicon/lint.xml @@ -1,3 +1,2 @@ <?xml version="1.0" encoding="utf-8"?> -<lint> -</lint>
\ No newline at end of file +<lint></lint>
\ No newline at end of file diff --git a/libs/emojicon/project.properties b/libs/emojicon/project.properties index 91d2b0246..414284d51 100644 --- a/libs/emojicon/project.properties +++ b/libs/emojicon/project.properties @@ -9,7 +9,6 @@ # # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - # Project target. target=android-19 android.library=true diff --git a/libs/emojicon/res/drawable/ic_emoji_nature_light.xml b/libs/emojicon/res/drawable/ic_emoji_nature_light.xml index 543409e03..87464fb1e 100644 --- a/libs/emojicon/res/drawable/ic_emoji_nature_light.xml +++ b/libs/emojicon/res/drawable/ic_emoji_nature_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,15 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_nature_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_nature_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_nature_light_activated" /> - <item - android:drawable="@drawable/ic_emoji_nature_light_normal" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_nature_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_nature_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_nature_light_activated" /> + <item android:drawable="@drawable/ic_emoji_nature_light_normal" /> </selector> diff --git a/libs/emojicon/res/drawable/ic_emoji_objects_light.xml b/libs/emojicon/res/drawable/ic_emoji_objects_light.xml index 4096e695b..74c80e3d0 100644 --- a/libs/emojicon/res/drawable/ic_emoji_objects_light.xml +++ b/libs/emojicon/res/drawable/ic_emoji_objects_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_objects_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_objects_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_objects_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_objects_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_objects_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_objects_light_activated" /> <item android:drawable="@drawable/ic_emoji_objects_light_normal" /> </selector> diff --git a/libs/emojicon/res/drawable/ic_emoji_people_light.xml b/libs/emojicon/res/drawable/ic_emoji_people_light.xml index ea9e406a4..06f7aebbf 100644 --- a/libs/emojicon/res/drawable/ic_emoji_people_light.xml +++ b/libs/emojicon/res/drawable/ic_emoji_people_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_people_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_people_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_people_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_people_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_people_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_people_light_activated" /> <item android:drawable="@drawable/ic_emoji_people_light_normal" /> </selector> diff --git a/libs/emojicon/res/drawable/ic_emoji_places_light.xml b/libs/emojicon/res/drawable/ic_emoji_places_light.xml index 312cad9c3..36f258876 100644 --- a/libs/emojicon/res/drawable/ic_emoji_places_light.xml +++ b/libs/emojicon/res/drawable/ic_emoji_places_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_places_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_places_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_places_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_places_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_places_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_places_light_activated" /> <item android:drawable="@drawable/ic_emoji_places_light_normal" /> </selector> diff --git a/libs/emojicon/res/drawable/ic_emoji_recent_light.xml b/libs/emojicon/res/drawable/ic_emoji_recent_light.xml index 8c2123f83..90f2c8565 100644 --- a/libs/emojicon/res/drawable/ic_emoji_recent_light.xml +++ b/libs/emojicon/res/drawable/ic_emoji_recent_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_recent_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_recent_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_recent_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_recent_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_recent_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_recent_light_activated" /> <item android:drawable="@drawable/ic_emoji_recent_light_normal" /> </selector> diff --git a/libs/emojicon/res/drawable/ic_emoji_symbols_light.xml b/libs/emojicon/res/drawable/ic_emoji_symbols_light.xml index 79aaf0fc5..9077c3289 100644 --- a/libs/emojicon/res/drawable/ic_emoji_symbols_light.xml +++ b/libs/emojicon/res/drawable/ic_emoji_symbols_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_symbols_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_symbols_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_symbols_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_symbols_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_symbols_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_symbols_light_activated" /> <item android:drawable="@drawable/ic_emoji_symbols_light_normal" /> </selector> diff --git a/libs/emojicon/res/drawable/orca_composer_attach_camera_button.xml b/libs/emojicon/res/drawable/orca_composer_attach_camera_button.xml index 0b255fb27..56e8d0484 100644 --- a/libs/emojicon/res/drawable/orca_composer_attach_camera_button.xml +++ b/libs/emojicon/res/drawable/orca_composer_attach_camera_button.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_attach_camera_pressed" /> <item android:drawable="@drawable/orca_attach_camera_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/res/drawable/orca_composer_attach_location_button.xml b/libs/emojicon/res/drawable/orca_composer_attach_location_button.xml index 4971113aa..be898ebcf 100644 --- a/libs/emojicon/res/drawable/orca_composer_attach_location_button.xml +++ b/libs/emojicon/res/drawable/orca_composer_attach_location_button.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2013 Klamr. All rights reserved. ~ ~ This software is the confidential and proprietary information of Klamr or one of its @@ -14,8 +13,7 @@ ~ ITS DERIVATIVES. --> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_pressed="true" android:drawable="@drawable/orca_attach_location_pressed"/> - <item android:drawable="@drawable/orca_attach_location_normal"/> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_pressed="true" android:drawable="@drawable/orca_attach_location_pressed" /> + <item android:drawable="@drawable/orca_attach_location_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/res/drawable/orca_composer_attach_photo_button.xml b/libs/emojicon/res/drawable/orca_composer_attach_photo_button.xml index ca7508dd9..21f8e8e6c 100644 --- a/libs/emojicon/res/drawable/orca_composer_attach_photo_button.xml +++ b/libs/emojicon/res/drawable/orca_composer_attach_photo_button.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_attach_photo_pressed" /> <item android:drawable="@drawable/orca_attach_photo_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/res/drawable/orca_composer_popup_button.xml b/libs/emojicon/res/drawable/orca_composer_popup_button.xml index d43dc26e4..dccfb4848 100644 --- a/libs/emojicon/res/drawable/orca_composer_popup_button.xml +++ b/libs/emojicon/res/drawable/orca_composer_popup_button.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_popup_pressed" /> <item android:drawable="@drawable/orca_composer_popup_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/res/drawable/orca_composer_popup_button_active.xml b/libs/emojicon/res/drawable/orca_composer_popup_button_active.xml index f5e40ef8c..556d0151b 100644 --- a/libs/emojicon/res/drawable/orca_composer_popup_button_active.xml +++ b/libs/emojicon/res/drawable/orca_composer_popup_button_active.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_popup_active_pressed" /> <item android:drawable="@drawable/orca_composer_popup_active_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/res/drawable/orca_emoji_backspace_front_button.xml b/libs/emojicon/res/drawable/orca_emoji_backspace_front_button.xml index a2d2f5b62..e922eb686 100644 --- a/libs/emojicon/res/drawable/orca_emoji_backspace_front_button.xml +++ b/libs/emojicon/res/drawable/orca_emoji_backspace_front_button.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_backspace_front_pressed"/> - <item android:drawable="@drawable/orca_emoji_backspace_front_normal"/> + <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_backspace_front_pressed" /> + <item android:drawable="@drawable/orca_emoji_backspace_front_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/res/drawable/orca_emoji_more_front_button.xml b/libs/emojicon/res/drawable/orca_emoji_more_front_button.xml index a799d56d9..3e0e9f6f0 100644 --- a/libs/emojicon/res/drawable/orca_emoji_more_front_button.xml +++ b/libs/emojicon/res/drawable/orca_emoji_more_front_button.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_more_front_pressed"/> - <item android:drawable="@drawable/orca_emoji_more_front_normal"/> + <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_more_front_pressed" /> + <item android:drawable="@drawable/orca_emoji_more_front_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/res/drawable/orca_emoji_tab_background.xml b/libs/emojicon/res/drawable/orca_emoji_tab_background.xml index f68e6212b..d597dc03a 100644 --- a/libs/emojicon/res/drawable/orca_emoji_tab_background.xml +++ b/libs/emojicon/res/drawable/orca_emoji_tab_background.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/orca_composer_tab_pressed" /> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_tab_active" /> <item android:drawable="@drawable/orca_composer_tab" /> diff --git a/libs/emojicon/res/drawable/orca_emoji_tab_dark_background.xml b/libs/emojicon/res/drawable/orca_emoji_tab_dark_background.xml index 07ff608c9..f0b0d1a66 100644 --- a/libs/emojicon/res/drawable/orca_emoji_tab_dark_background.xml +++ b/libs/emojicon/res/drawable/orca_emoji_tab_dark_background.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2013 Klamr. All rights reserved. ~ ~ This software is the confidential and proprietary information of Klamr or one of its @@ -14,8 +13,7 @@ ~ ITS DERIVATIVES. --> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_tab_pressed" /> <item android:drawable="@drawable/orca_composer_tab_active" android:state_checked="true" /> <item android:drawable="@drawable/orca_composer_tab_dark" /> diff --git a/libs/emojicon/res/layout/emojicon_grid.xml b/libs/emojicon/res/layout/emojicon_grid.xml index 457f8756b..7e1579c3f 100644 --- a/libs/emojicon/res/layout/emojicon_grid.xml +++ b/libs/emojicon/res/layout/emojicon_grid.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2013 Klamr. All rights reserved. ~ ~ This software is the confidential and proprietary information of Klamr or one of its diff --git a/libs/emojicon/res/layout/emojicon_item.xml b/libs/emojicon/res/layout/emojicon_item.xml index ed11041a7..a85b1b640 100644 --- a/libs/emojicon/res/layout/emojicon_item.xml +++ b/libs/emojicon/res/layout/emojicon_item.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright 2014 Ankush Sachdeva ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,18 +14,18 @@ ~ limitations under the License. --> -<FrameLayout - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:emojicon="http://schemas.android.com/apk/res-auto" - android:layout_width="wrap_content" - android:layout_height="wrap_content"> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:emojicon="http://schemas.android.com/apk/res-auto" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + <github.ankushsachdeva.emojicon.EmojiconTextView - android:layout_gravity="center" - android:id="@+id/emojicon_icon" - android:layout_width="36dip" - android:layout_height="36dip" - emojicon:emojiconSize="30dip" - android:focusable="false" - android:focusableInTouchMode="false" - android:gravity="center"/> + android:layout_gravity="center" + android:id="@+id/emojicon_icon" + android:layout_width="36dip" + android:layout_height="36dip" + emojicon:emojiconSize="30dip" + android:focusable="false" + android:focusableInTouchMode="false" + android:gravity="center" /> </FrameLayout>
\ No newline at end of file diff --git a/libs/emojicon/res/layout/emojicons.xml b/libs/emojicon/res/layout/emojicons.xml index 287923d1b..e61c2fb34 100644 --- a/libs/emojicon/res/layout/emojicons.xml +++ b/libs/emojicon/res/layout/emojicons.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright 2014 Ankush Sachdeva ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,104 +15,120 @@ --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:background="@drawable/keyboard_background_holo" - android:layout_width="match_parent" - android:layout_height="match_parent"> + android:background="@drawable/keyboard_background_holo" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <LinearLayout - android:id="@+id/emojis_tab" - android:layout_width="match_parent" - android:layout_height="50dip" - android:layout_alignParentTop="true" - android:orientation="horizontal"> + android:id="@+id/emojis_tab" + android:layout_width="match_parent" + android:layout_height="50dip" + android:layout_alignParentTop="true" + android:orientation="horizontal"> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_0_recents" - android:src="@drawable/ic_emoji_recent_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_0_recents" + android:src="@drawable/ic_emoji_recent_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_1_people" - android:src="@drawable/ic_emoji_people_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_1_people" + android:src="@drawable/ic_emoji_people_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_2_nature" - android:src="@drawable/ic_emoji_nature_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_2_nature" + android:src="@drawable/ic_emoji_nature_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_3_objects" - android:src="@drawable/ic_emoji_objects_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_3_objects" + android:src="@drawable/ic_emoji_objects_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_4_cars" - android:src="@drawable/ic_emoji_places_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_4_cars" + android:src="@drawable/ic_emoji_places_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_5_punctuation" - android:src="@drawable/ic_emoji_symbols_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_5_punctuation" + android:src="@drawable/ic_emoji_symbols_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:id="@+id/emojis_backspace" - android:src="@drawable/sym_keyboard_delete_holo_dark"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:id="@+id/emojis_backspace" + android:src="@drawable/sym_keyboard_delete_holo_dark" /> </LinearLayout> + <android.support.v4.view.ViewPager android:layout_below="@id/emojis_tab" android:id="@+id/emojis_pager" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentBottom="true"/> + android:layout_alignParentBottom="true" /> + <View android:layout_width="match_parent" android:layout_height="1px" android:layout_below="@id/emojis_tab" - android:background="#8f8f8f"/> + android:background="#8f8f8f" /> </RelativeLayout> diff --git a/libs/emojicon/res/values/attrs.xml b/libs/emojicon/res/values/attrs.xml index 9810158dc..f4f21f903 100644 --- a/libs/emojicon/res/values/attrs.xml +++ b/libs/emojicon/res/values/attrs.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright 2014 Ankush Sachdeva ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiAdapter.java b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiAdapter.java index 347870c9d..18842ea0d 100644 --- a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiAdapter.java +++ b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiAdapter.java @@ -33,7 +33,8 @@ import github.ankushsachdeva.emojicon.emoji.Emojicon; * @author Ankush Sachdeva (sankush@yahoo.co.in) */ class EmojiAdapter extends ArrayAdapter<Emojicon> { - OnEmojiconClickedListener emojiClickListener; + OnEmojiconClickedListener emojiClickListener; + public EmojiAdapter(Context context, List<Emojicon> data) { super(context, R.layout.emojicon_item, data); } @@ -41,11 +42,11 @@ class EmojiAdapter extends ArrayAdapter<Emojicon> { public EmojiAdapter(Context context, Emojicon[] data) { super(context, R.layout.emojicon_item, data); } - - public void setEmojiClickListener(OnEmojiconClickedListener listener){ - this.emojiClickListener = listener; + + public void setEmojiClickListener(OnEmojiconClickedListener listener) { + this.emojiClickListener = listener; } - + @Override public View getView(final int position, View convertView, ViewGroup parent) { View v = convertView; @@ -59,11 +60,11 @@ class EmojiAdapter extends ArrayAdapter<Emojicon> { ViewHolder holder = (ViewHolder) v.getTag(); holder.icon.setText(emoji.getEmoji()); holder.icon.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - emojiClickListener.onEmojiconClicked(getItem(position)); - } - }); + @Override + public void onClick(View v) { + emojiClickListener.onEmojiconClicked(getItem(position)); + } + }); return v; } diff --git a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconGridView.java b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconGridView.java index 10379129c..72087e6e6 100644 --- a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconGridView.java +++ b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconGridView.java @@ -30,48 +30,48 @@ import github.ankushsachdeva.emojicon.emoji.People; /** * @author Hieu Rocker (rockerhieu@gmail.com) - * @author Ankush Sachdeva (sankush@yahoo.co.in) + * @author Ankush Sachdeva (sankush@yahoo.co.in) */ -public class EmojiconGridView{ - public View rootView; - EmojiconsPopup mEmojiconPopup; +public class EmojiconGridView { + public View rootView; + EmojiconsPopup mEmojiconPopup; EmojiconRecents mRecents; Emojicon[] mData; - + public EmojiconGridView(Context context, Emojicon[] emojicons, EmojiconRecents recents, EmojiconsPopup emojiconPopup) { - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); - mEmojiconPopup = emojiconPopup; - rootView = inflater.inflate(R.layout.emojicon_grid, null); - setRecents(recents); - GridView gridView = (GridView) rootView.findViewById(R.id.Emoji_GridView); - if (emojicons== null) { - mData = People.DATA; - } else { - Object[] o = (Object[]) emojicons; - mData = Arrays.asList(o).toArray(new Emojicon[o.length]); - } - EmojiAdapter mAdapter = new EmojiAdapter(rootView.getContext(), mData); - mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { - - @Override - public void onEmojiconClicked(Emojicon emojicon) { - if (mEmojiconPopup.onEmojiconClickedListener != null) { - mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); - } - if (mRecents != null) { - mRecents.addRecentEmoji(rootView.getContext(), emojicon); - } - } - }); - gridView.setAdapter(mAdapter); - } - - private void setRecents(EmojiconRecents recents) { + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); + mEmojiconPopup = emojiconPopup; + rootView = inflater.inflate(R.layout.emojicon_grid, null); + setRecents(recents); + GridView gridView = (GridView) rootView.findViewById(R.id.Emoji_GridView); + if (emojicons == null) { + mData = People.DATA; + } else { + Object[] o = (Object[]) emojicons; + mData = Arrays.asList(o).toArray(new Emojicon[o.length]); + } + EmojiAdapter mAdapter = new EmojiAdapter(rootView.getContext(), mData); + mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { + + @Override + public void onEmojiconClicked(Emojicon emojicon) { + if (mEmojiconPopup.onEmojiconClickedListener != null) { + mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); + } + if (mRecents != null) { + mRecents.addRecentEmoji(rootView.getContext(), emojicon); + } + } + }); + gridView.setAdapter(mAdapter); + } + + private void setRecents(EmojiconRecents recents) { mRecents = recents; } public interface OnEmojiconClickedListener { void onEmojiconClicked(Emojicon emojicon); } - + } diff --git a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconHandler.java b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconHandler.java index bc7a228c0..84f087d86 100644 --- a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconHandler.java +++ b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconHandler.java @@ -1396,7 +1396,7 @@ public final class EmojiconHandler { public static void addEmojis(Context context, Spannable text, int emojiSize, int index, int length) { int textLength = text.length(); int textLengthToProcessMax = textLength - index; - int textLengthToProcess = length < 0 || length >= textLengthToProcessMax ? textLength : (length+index); + int textLengthToProcess = length < 0 || length >= textLengthToProcessMax ? textLength : (length + index); // remove spans throughout all text EmojiconSpan[] oldSpans = text.getSpans(0, textLength, EmojiconSpan.class); diff --git a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecents.java b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecents.java index c7a90c837..e3274ed77 100644 --- a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecents.java +++ b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecents.java @@ -21,8 +21,8 @@ import android.content.Context; import github.ankushsachdeva.emojicon.emoji.Emojicon; /** -* @author Daniele Ricci -*/ + * @author Daniele Ricci + */ public interface EmojiconRecents { public void addRecentEmoji(Context context, Emojicon emojicon); } diff --git a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java index ea98c809d..ff65ac06d 100644 --- a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java +++ b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java @@ -24,26 +24,26 @@ import github.ankushsachdeva.emojicon.emoji.Emojicon; /** * @author Daniele Ricci - * @author Ankush Sachdeva (sankush@yahoo.co.in) + * @author Ankush Sachdeva (sankush@yahoo.co.in) */ public class EmojiconRecentsGridView extends EmojiconGridView implements EmojiconRecents { - EmojiAdapter mAdapter; - - public EmojiconRecentsGridView(Context context, Emojicon[] emojicons, - EmojiconRecents recents,EmojiconsPopup emojiconsPopup) { - super(context, emojicons, recents, emojiconsPopup); - EmojiconRecentsManager recents1 = EmojiconRecentsManager - .getInstance(rootView.getContext()); - mAdapter = new EmojiAdapter(rootView.getContext(), recents1); - mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { - - @Override - public void onEmojiconClicked(Emojicon emojicon) { - if (mEmojiconPopup.onEmojiconClickedListener != null) { - mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); - } - } - }); + EmojiAdapter mAdapter; + + public EmojiconRecentsGridView(Context context, Emojicon[] emojicons, + EmojiconRecents recents, EmojiconsPopup emojiconsPopup) { + super(context, emojicons, recents, emojiconsPopup); + EmojiconRecentsManager recents1 = EmojiconRecentsManager + .getInstance(rootView.getContext()); + mAdapter = new EmojiAdapter(rootView.getContext(), recents1); + mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { + + @Override + public void onEmojiconClicked(Emojicon emojicon) { + if (mEmojiconPopup.onEmojiconClickedListener != null) { + mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); + } + } + }); GridView gridView = (GridView) rootView.findViewById(R.id.Emoji_GridView); gridView.setAdapter(mAdapter); } @@ -51,7 +51,7 @@ public class EmojiconRecentsGridView extends EmojiconGridView implements Emojico @Override public void addRecentEmoji(Context context, Emojicon emojicon) { EmojiconRecentsManager recents = EmojiconRecentsManager - .getInstance(context); + .getInstance(context); recents.push(emojicon); // notify dataset changed diff --git a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java index 177f11591..f208b10c4 100644 --- a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java +++ b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java @@ -26,8 +26,8 @@ import github.ankushsachdeva.emojicon.emoji.Emojicon; /** -* @author Daniele Ricci -*/ + * @author Daniele Ricci + */ public class EmojiconRecentsManager extends ArrayList<Emojicon> { private static final String PREFERENCE_NAME = "emojicon"; @@ -88,7 +88,7 @@ public class EmojiconRecentsManager extends ArrayList<Emojicon> { boolean ret = super.remove(object); return ret; } - + private SharedPreferences getPreferences() { return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); } @@ -99,14 +99,13 @@ public class EmojiconRecentsManager extends ArrayList<Emojicon> { StringTokenizer tokenizer = new StringTokenizer(str, "~"); while (tokenizer.hasMoreTokens()) { try { - add(new Emojicon(tokenizer.nextToken())); - } - catch (NumberFormatException e) { + add(new Emojicon(tokenizer.nextToken())); + } catch (NumberFormatException e) { // ignored } } } - + public void saveRecents() { StringBuilder str = new StringBuilder(); int c = size(); diff --git a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconsPopup.java b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconsPopup.java index 2a35aa9c0..f7d68ddc5 100644 --- a/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconsPopup.java +++ b/libs/emojicon/src/github/ankushsachdeva/emojicon/EmojiconsPopup.java @@ -53,372 +53,376 @@ import github.ankushsachdeva.emojicon.emoji.Symbols; */ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChangeListener, EmojiconRecents { - private int mEmojiTabLastSelectedIndex = -1; - private View[] mEmojiTabs; - private PagerAdapter mEmojisAdapter; - private EmojiconRecentsManager mRecentsManager; - private int keyBoardHeight = 0; - private Boolean pendingOpen = false; - private Boolean isOpened = false; - OnEmojiconClickedListener onEmojiconClickedListener; - OnEmojiconBackspaceClickedListener onEmojiconBackspaceClickedListener; - OnSoftKeyboardOpenCloseListener onSoftKeyboardOpenCloseListener; - View rootView; - Context mContext; - - private ViewPager emojisPager; - /** - * Constructor - * @param rootView The top most layout in your view hierarchy. The difference of this view and the screen height will be used to calculate the keyboard height. - * @param mContext The context of current activity. - */ - public EmojiconsPopup(View rootView, Context mContext){ - super(mContext); - this.mContext = mContext; - this.rootView = rootView; - View customView = createCustomView(); - setContentView(customView); - setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); - //default size - setSize((int) mContext.getResources().getDimension(R.dimen.keyboard_height), LayoutParams.MATCH_PARENT); - } - /** - * Set the listener for the event of keyboard opening or closing. - */ - public void setOnSoftKeyboardOpenCloseListener(OnSoftKeyboardOpenCloseListener listener){ - this.onSoftKeyboardOpenCloseListener = listener; - } - - /** - * Set the listener for the event when any of the emojicon is clicked - */ - public void setOnEmojiconClickedListener(OnEmojiconClickedListener listener){ - this.onEmojiconClickedListener = listener; - } - - /** - * Set the listener for the event when backspace on emojicon popup is clicked - */ - public void setOnEmojiconBackspaceClickedListener(OnEmojiconBackspaceClickedListener listener){ - this.onEmojiconBackspaceClickedListener = listener; - } - - /** - * Use this function to show the emoji popup. - * NOTE: Since, the soft keyboard sizes are variable on different android devices, the - * library needs you to open the soft keyboard atleast once before calling this function. - * If that is not possible see showAtBottomPending() function. - * - */ - public void showAtBottom(){ - showAtLocation(rootView, Gravity.BOTTOM, 0, 0); - } - /** - * Use this function when the soft keyboard has not been opened yet. This - * will show the emoji popup after the keyboard is up next time. - * Generally, you will be calling InputMethodManager.showSoftInput function after - * calling this function. - */ - public void showAtBottomPending(){ - if(isKeyBoardOpen()) - showAtBottom(); - else - pendingOpen = true; - } - - /** - * - * @return Returns true if the soft keyboard is open, false otherwise. - */ - public Boolean isKeyBoardOpen(){ - return isOpened; - } - - /** - * Dismiss the popup - */ - @Override - public void dismiss() { - super.dismiss(); - EmojiconRecentsManager - .getInstance(mContext).saveRecents(); - } - - /** - * Call this function to resize the emoji popup according to your soft keyboard size - */ - public void setSizeForSoftKeyboard(){ - rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - Rect r = new Rect(); - rootView.getWindowVisibleDisplayFrame(r); - - int screenHeight = getUsableScreenHeight(); - int heightDifference = screenHeight - - (r.bottom - r.top); - int resourceId = mContext.getResources() - .getIdentifier("status_bar_height", - "dimen", "android"); - if (resourceId > 0) { - heightDifference -= mContext.getResources() - .getDimensionPixelSize(resourceId); - } - if (heightDifference > 100) { - keyBoardHeight = heightDifference; - setSize(LayoutParams.MATCH_PARENT, keyBoardHeight); - if(isOpened == false){ - if(onSoftKeyboardOpenCloseListener!=null) - onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight); - } - isOpened = true; - if(pendingOpen){ - showAtBottom(); - pendingOpen = false; - } - } - else{ - isOpened = false; - if(onSoftKeyboardOpenCloseListener!=null) - onSoftKeyboardOpenCloseListener.onKeyboardClose(); - } - } - }); - } - - private int getUsableScreenHeight() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - DisplayMetrics metrics = new DisplayMetrics(); - - WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); - windowManager.getDefaultDisplay().getMetrics(metrics); - - return metrics.heightPixels; - - } else { - return rootView.getRootView().getHeight(); - } - } - - /** - * Manually set the popup window size - * @param width Width of the popup - * @param height Height of the popup - */ - public void setSize(int width, int height){ - setWidth(width); - setHeight(height); - } - - private View createCustomView() { - LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(R.layout.emojicons, null, false); - emojisPager = (ViewPager) view.findViewById(R.id.emojis_pager); - emojisPager.setOnPageChangeListener(this); - EmojiconRecents recents = this; - mEmojisAdapter = new EmojisPagerAdapter( - Arrays.asList( - new EmojiconRecentsGridView(mContext, null, null, this), - new EmojiconGridView(mContext, People.DATA, recents, this), - new EmojiconGridView(mContext, Nature.DATA, recents, this), - new EmojiconGridView(mContext, Objects.DATA, recents, this), - new EmojiconGridView(mContext, Places.DATA, recents, this), - new EmojiconGridView(mContext, Symbols.DATA, recents, this) - ) - ); - emojisPager.setAdapter(mEmojisAdapter); - mEmojiTabs = new View[6]; - mEmojiTabs[0] = view.findViewById(R.id.emojis_tab_0_recents); - mEmojiTabs[1] = view.findViewById(R.id.emojis_tab_1_people); - mEmojiTabs[2] = view.findViewById(R.id.emojis_tab_2_nature); - mEmojiTabs[3] = view.findViewById(R.id.emojis_tab_3_objects); - mEmojiTabs[4] = view.findViewById(R.id.emojis_tab_4_cars); - mEmojiTabs[5] = view.findViewById(R.id.emojis_tab_5_punctuation); - for (int i = 0; i < mEmojiTabs.length; i++) { - final int position = i; - mEmojiTabs[i].setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - emojisPager.setCurrentItem(position); - } - }); - } - view.findViewById(R.id.emojis_backspace).setOnTouchListener(new RepeatListener(1000, 50, new OnClickListener() { - - @Override - public void onClick(View v) { - if(onEmojiconBackspaceClickedListener != null) - onEmojiconBackspaceClickedListener.onEmojiconBackspaceClicked(v); - } - })); - - // get last selected page - mRecentsManager = EmojiconRecentsManager.getInstance(view.getContext()); - int page = mRecentsManager.getRecentPage(); - // last page was recents, check if there are recents to use - // if none was found, go to page 1 - if (page == 0 && mRecentsManager.size() == 0) { - page = 1; - } - - if (page == 0) { - onPageSelected(page); - } - else { - emojisPager.setCurrentItem(page, false); - } - return view; - } - - @Override - public void addRecentEmoji(Context context, Emojicon emojicon) { - EmojiconRecentsGridView fragment = ((EmojisPagerAdapter)emojisPager.getAdapter()).getRecentFragment(); - fragment.addRecentEmoji(context, emojicon); - } - - - @Override - public void onPageScrolled(int i, float v, int i2) { - } - - @Override - public void onPageSelected(int i) { - if (mEmojiTabLastSelectedIndex == i) { - return; - } - switch (i) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - if (mEmojiTabLastSelectedIndex >= 0 && mEmojiTabLastSelectedIndex < mEmojiTabs.length) { - mEmojiTabs[mEmojiTabLastSelectedIndex].setSelected(false); - } - mEmojiTabs[i].setSelected(true); - mEmojiTabLastSelectedIndex = i; - mRecentsManager.setRecentPage(i); - break; - } - } - - @Override - public void onPageScrollStateChanged(int i) { - } - - private static class EmojisPagerAdapter extends PagerAdapter { - private List<EmojiconGridView> views; - public EmojiconRecentsGridView getRecentFragment(){ - for (EmojiconGridView it : views) { - if(it instanceof EmojiconRecentsGridView) - return (EmojiconRecentsGridView)it; - } - return null; - } - public EmojisPagerAdapter(List<EmojiconGridView> views) { - super(); - this.views = views; - } - - @Override - public int getCount() { - return views.size(); - } - - - @Override - public Object instantiateItem(ViewGroup container, int position) { - View v = views.get(position).rootView; - ((ViewPager)container).addView(v, 0); - return v; - } - - @Override - public void destroyItem(ViewGroup container, int position, Object view) { - ((ViewPager)container).removeView((View)view); - } - - @Override - public boolean isViewFromObject(View view, Object key) { - return key == view; - } - } - - /** - * A class, that can be used as a TouchListener on any view (e.g. a Button). - * It cyclically runs a clickListener, emulating keyboard-like behaviour. First - * click is fired immediately, next before initialInterval, and subsequent before - * normalInterval. - * <p/> - * <p>Interval is scheduled before the onClick completes, so it has to run fast. - * If it runs slow, it does not generate skipped onClicks. - */ - public static class RepeatListener implements View.OnTouchListener { - - private Handler handler = new Handler(); - - private int initialInterval; - private final int normalInterval; - private final View.OnClickListener clickListener; - - private Runnable handlerRunnable = new Runnable() { - @Override - public void run() { - if (downView == null) { - return; - } - handler.removeCallbacksAndMessages(downView); - handler.postAtTime(this, downView, SystemClock.uptimeMillis() + normalInterval); - clickListener.onClick(downView); - } - }; - - private View downView; - - /** - * @param initialInterval The interval before first click event - * @param normalInterval The interval before second and subsequent click - * events - * @param clickListener The OnClickListener, that will be called - * periodically - */ - public RepeatListener(int initialInterval, int normalInterval, View.OnClickListener clickListener) { - if (clickListener == null) - throw new IllegalArgumentException("null runnable"); - if (initialInterval < 0 || normalInterval < 0) - throw new IllegalArgumentException("negative interval"); - - this.initialInterval = initialInterval; - this.normalInterval = normalInterval; - this.clickListener = clickListener; - } - - public boolean onTouch(View view, MotionEvent motionEvent) { - switch (motionEvent.getAction()) { - case MotionEvent.ACTION_DOWN: - downView = view; - handler.removeCallbacks(handlerRunnable); - handler.postAtTime(handlerRunnable, downView, SystemClock.uptimeMillis() + initialInterval); - clickListener.onClick(view); - return true; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_OUTSIDE: - handler.removeCallbacksAndMessages(downView); - downView = null; - return true; - } - return false; - } - } - - public interface OnEmojiconBackspaceClickedListener { - void onEmojiconBackspaceClicked(View v); - } - - public interface OnSoftKeyboardOpenCloseListener{ - void onKeyboardOpen(int keyBoardHeight); - void onKeyboardClose(); - } + private int mEmojiTabLastSelectedIndex = -1; + private View[] mEmojiTabs; + private PagerAdapter mEmojisAdapter; + private EmojiconRecentsManager mRecentsManager; + private int keyBoardHeight = 0; + private Boolean pendingOpen = false; + private Boolean isOpened = false; + OnEmojiconClickedListener onEmojiconClickedListener; + OnEmojiconBackspaceClickedListener onEmojiconBackspaceClickedListener; + OnSoftKeyboardOpenCloseListener onSoftKeyboardOpenCloseListener; + View rootView; + Context mContext; + + private ViewPager emojisPager; + + /** + * Constructor + * + * @param rootView The top most layout in your view hierarchy. The difference of this view and the screen height will be used to calculate the keyboard height. + * @param mContext The context of current activity. + */ + public EmojiconsPopup(View rootView, Context mContext) { + super(mContext); + this.mContext = mContext; + this.rootView = rootView; + View customView = createCustomView(); + setContentView(customView); + setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + //default size + setSize((int) mContext.getResources().getDimension(R.dimen.keyboard_height), LayoutParams.MATCH_PARENT); + } + + /** + * Set the listener for the event of keyboard opening or closing. + */ + public void setOnSoftKeyboardOpenCloseListener(OnSoftKeyboardOpenCloseListener listener) { + this.onSoftKeyboardOpenCloseListener = listener; + } + + /** + * Set the listener for the event when any of the emojicon is clicked + */ + public void setOnEmojiconClickedListener(OnEmojiconClickedListener listener) { + this.onEmojiconClickedListener = listener; + } + + /** + * Set the listener for the event when backspace on emojicon popup is clicked + */ + public void setOnEmojiconBackspaceClickedListener(OnEmojiconBackspaceClickedListener listener) { + this.onEmojiconBackspaceClickedListener = listener; + } + + /** + * Use this function to show the emoji popup. + * NOTE: Since, the soft keyboard sizes are variable on different android devices, the + * library needs you to open the soft keyboard atleast once before calling this function. + * If that is not possible see showAtBottomPending() function. + */ + public void showAtBottom() { + showAtLocation(rootView, Gravity.BOTTOM, 0, 0); + } + + /** + * Use this function when the soft keyboard has not been opened yet. This + * will show the emoji popup after the keyboard is up next time. + * Generally, you will be calling InputMethodManager.showSoftInput function after + * calling this function. + */ + public void showAtBottomPending() { + if (isKeyBoardOpen()) + showAtBottom(); + else + pendingOpen = true; + } + + /** + * @return Returns true if the soft keyboard is open, false otherwise. + */ + public Boolean isKeyBoardOpen() { + return isOpened; + } + + /** + * Dismiss the popup + */ + @Override + public void dismiss() { + super.dismiss(); + EmojiconRecentsManager + .getInstance(mContext).saveRecents(); + } + + /** + * Call this function to resize the emoji popup according to your soft keyboard size + */ + public void setSizeForSoftKeyboard() { + rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + Rect r = new Rect(); + rootView.getWindowVisibleDisplayFrame(r); + + int screenHeight = getUsableScreenHeight(); + int heightDifference = screenHeight + - (r.bottom - r.top); + int resourceId = mContext.getResources() + .getIdentifier("status_bar_height", + "dimen", "android"); + if (resourceId > 0) { + heightDifference -= mContext.getResources() + .getDimensionPixelSize(resourceId); + } + if (heightDifference > 100) { + keyBoardHeight = heightDifference; + setSize(LayoutParams.MATCH_PARENT, keyBoardHeight); + if (isOpened == false) { + if (onSoftKeyboardOpenCloseListener != null) + onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight); + } + isOpened = true; + if (pendingOpen) { + showAtBottom(); + pendingOpen = false; + } + } else { + isOpened = false; + if (onSoftKeyboardOpenCloseListener != null) + onSoftKeyboardOpenCloseListener.onKeyboardClose(); + } + } + }); + } + + private int getUsableScreenHeight() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + DisplayMetrics metrics = new DisplayMetrics(); + + WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); + windowManager.getDefaultDisplay().getMetrics(metrics); + + return metrics.heightPixels; + + } else { + return rootView.getRootView().getHeight(); + } + } + + /** + * Manually set the popup window size + * + * @param width Width of the popup + * @param height Height of the popup + */ + public void setSize(int width, int height) { + setWidth(width); + setHeight(height); + } + + private View createCustomView() { + LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.emojicons, null, false); + emojisPager = (ViewPager) view.findViewById(R.id.emojis_pager); + emojisPager.setOnPageChangeListener(this); + EmojiconRecents recents = this; + mEmojisAdapter = new EmojisPagerAdapter( + Arrays.asList( + new EmojiconRecentsGridView(mContext, null, null, this), + new EmojiconGridView(mContext, People.DATA, recents, this), + new EmojiconGridView(mContext, Nature.DATA, recents, this), + new EmojiconGridView(mContext, Objects.DATA, recents, this), + new EmojiconGridView(mContext, Places.DATA, recents, this), + new EmojiconGridView(mContext, Symbols.DATA, recents, this) + ) + ); + emojisPager.setAdapter(mEmojisAdapter); + mEmojiTabs = new View[6]; + mEmojiTabs[0] = view.findViewById(R.id.emojis_tab_0_recents); + mEmojiTabs[1] = view.findViewById(R.id.emojis_tab_1_people); + mEmojiTabs[2] = view.findViewById(R.id.emojis_tab_2_nature); + mEmojiTabs[3] = view.findViewById(R.id.emojis_tab_3_objects); + mEmojiTabs[4] = view.findViewById(R.id.emojis_tab_4_cars); + mEmojiTabs[5] = view.findViewById(R.id.emojis_tab_5_punctuation); + for (int i = 0; i < mEmojiTabs.length; i++) { + final int position = i; + mEmojiTabs[i].setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + emojisPager.setCurrentItem(position); + } + }); + } + view.findViewById(R.id.emojis_backspace).setOnTouchListener(new RepeatListener(1000, 50, new OnClickListener() { + + @Override + public void onClick(View v) { + if (onEmojiconBackspaceClickedListener != null) + onEmojiconBackspaceClickedListener.onEmojiconBackspaceClicked(v); + } + })); + + // get last selected page + mRecentsManager = EmojiconRecentsManager.getInstance(view.getContext()); + int page = mRecentsManager.getRecentPage(); + // last page was recents, check if there are recents to use + // if none was found, go to page 1 + if (page == 0 && mRecentsManager.size() == 0) { + page = 1; + } + + if (page == 0) { + onPageSelected(page); + } else { + emojisPager.setCurrentItem(page, false); + } + return view; + } + + @Override + public void addRecentEmoji(Context context, Emojicon emojicon) { + EmojiconRecentsGridView fragment = ((EmojisPagerAdapter) emojisPager.getAdapter()).getRecentFragment(); + fragment.addRecentEmoji(context, emojicon); + } + + + @Override + public void onPageScrolled(int i, float v, int i2) { + } + + @Override + public void onPageSelected(int i) { + if (mEmojiTabLastSelectedIndex == i) { + return; + } + switch (i) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + if (mEmojiTabLastSelectedIndex >= 0 && mEmojiTabLastSelectedIndex < mEmojiTabs.length) { + mEmojiTabs[mEmojiTabLastSelectedIndex].setSelected(false); + } + mEmojiTabs[i].setSelected(true); + mEmojiTabLastSelectedIndex = i; + mRecentsManager.setRecentPage(i); + break; + } + } + + @Override + public void onPageScrollStateChanged(int i) { + } + + private static class EmojisPagerAdapter extends PagerAdapter { + private List<EmojiconGridView> views; + + public EmojiconRecentsGridView getRecentFragment() { + for (EmojiconGridView it : views) { + if (it instanceof EmojiconRecentsGridView) + return (EmojiconRecentsGridView) it; + } + return null; + } + + public EmojisPagerAdapter(List<EmojiconGridView> views) { + super(); + this.views = views; + } + + @Override + public int getCount() { + return views.size(); + } + + + @Override + public Object instantiateItem(ViewGroup container, int position) { + View v = views.get(position).rootView; + ((ViewPager) container).addView(v, 0); + return v; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object view) { + ((ViewPager) container).removeView((View) view); + } + + @Override + public boolean isViewFromObject(View view, Object key) { + return key == view; + } + } + + /** + * A class, that can be used as a TouchListener on any view (e.g. a Button). + * It cyclically runs a clickListener, emulating keyboard-like behaviour. First + * click is fired immediately, next before initialInterval, and subsequent before + * normalInterval. + * <p/> + * <p>Interval is scheduled before the onClick completes, so it has to run fast. + * If it runs slow, it does not generate skipped onClicks. + */ + public static class RepeatListener implements View.OnTouchListener { + + private Handler handler = new Handler(); + + private int initialInterval; + private final int normalInterval; + private final View.OnClickListener clickListener; + + private Runnable handlerRunnable = new Runnable() { + @Override + public void run() { + if (downView == null) { + return; + } + handler.removeCallbacksAndMessages(downView); + handler.postAtTime(this, downView, SystemClock.uptimeMillis() + normalInterval); + clickListener.onClick(downView); + } + }; + + private View downView; + + /** + * @param initialInterval The interval before first click event + * @param normalInterval The interval before second and subsequent click + * events + * @param clickListener The OnClickListener, that will be called + * periodically + */ + public RepeatListener(int initialInterval, int normalInterval, View.OnClickListener clickListener) { + if (clickListener == null) + throw new IllegalArgumentException("null runnable"); + if (initialInterval < 0 || normalInterval < 0) + throw new IllegalArgumentException("negative interval"); + + this.initialInterval = initialInterval; + this.normalInterval = normalInterval; + this.clickListener = clickListener; + } + + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + downView = view; + handler.removeCallbacks(handlerRunnable); + handler.postAtTime(handlerRunnable, downView, SystemClock.uptimeMillis() + initialInterval); + clickListener.onClick(view); + return true; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_OUTSIDE: + handler.removeCallbacksAndMessages(downView); + downView = null; + return true; + } + return false; + } + } + + public interface OnEmojiconBackspaceClickedListener { + void onEmojiconBackspaceClicked(View v); + } + + public interface OnSoftKeyboardOpenCloseListener { + void onKeyboardOpen(int keyBoardHeight); + + void onKeyboardClose(); + } } diff --git a/libs/emojicon/src/main/AndroidManifest.xml b/libs/emojicon/src/main/AndroidManifest.xml index a07b8e21b..135e6fec5 100644 --- a/libs/emojicon/src/main/AndroidManifest.xml +++ b/libs/emojicon/src/main/AndroidManifest.xml @@ -1,9 +1,12 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="github.ankushsachdeva.emojicon"> - <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/> + <uses-sdk + android:minSdkVersion="8" + android:targetSdkVersion="19" /> - <application android:allowBackup="true" + <application + android:allowBackup="true" android:label="@string/app_name" android:icon="@drawable/ic_launcher"> diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiAdapter.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiAdapter.java index e33d8d6b9..c6efb45a3 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiAdapter.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiAdapter.java @@ -32,7 +32,8 @@ import github.ankushsachdeva.emojicon.emoji.Emojicon; * @author Ankush Sachdeva (sankush@yahoo.co.in) */ class EmojiAdapter extends ArrayAdapter<Emojicon> { - OnEmojiconClickedListener emojiClickListener; + OnEmojiconClickedListener emojiClickListener; + public EmojiAdapter(Context context, List<Emojicon> data) { super(context, R.layout.emojicon_item, data); } @@ -40,11 +41,11 @@ class EmojiAdapter extends ArrayAdapter<Emojicon> { public EmojiAdapter(Context context, Emojicon[] data) { super(context, R.layout.emojicon_item, data); } - - public void setEmojiClickListener(OnEmojiconClickedListener listener){ - this.emojiClickListener = listener; + + public void setEmojiClickListener(OnEmojiconClickedListener listener) { + this.emojiClickListener = listener; } - + @Override public View getView(final int position, View convertView, ViewGroup parent) { View v = convertView; @@ -58,11 +59,11 @@ class EmojiAdapter extends ArrayAdapter<Emojicon> { ViewHolder holder = (ViewHolder) v.getTag(); holder.icon.setText(emoji.getEmoji()); holder.icon.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - emojiClickListener.onEmojiconClicked(getItem(position)); - } - }); + @Override + public void onClick(View v) { + emojiClickListener.onEmojiconClicked(getItem(position)); + } + }); return v; } diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconGridView.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconGridView.java index 1f2c6bb46..1feda8ac6 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconGridView.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconGridView.java @@ -29,48 +29,48 @@ import github.ankushsachdeva.emojicon.emoji.People; /** * @author Hieu Rocker (rockerhieu@gmail.com) - * @author Ankush Sachdeva (sankush@yahoo.co.in) + * @author Ankush Sachdeva (sankush@yahoo.co.in) */ -public class EmojiconGridView{ - public View rootView; - EmojiconsPopup mEmojiconPopup; +public class EmojiconGridView { + public View rootView; + EmojiconsPopup mEmojiconPopup; EmojiconRecents mRecents; Emojicon[] mData; - + public EmojiconGridView(Context context, Emojicon[] emojicons, EmojiconRecents recents, EmojiconsPopup emojiconPopup) { - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); - mEmojiconPopup = emojiconPopup; - rootView = inflater.inflate(R.layout.emojicon_grid, null); - setRecents(recents); - GridView gridView = (GridView) rootView.findViewById(R.id.Emoji_GridView); - if (emojicons== null) { - mData = People.DATA; - } else { - Object[] o = (Object[]) emojicons; - mData = Arrays.asList(o).toArray(new Emojicon[o.length]); - } - EmojiAdapter mAdapter = new EmojiAdapter(rootView.getContext(), mData); - mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { - - @Override - public void onEmojiconClicked(Emojicon emojicon) { - if (mEmojiconPopup.onEmojiconClickedListener != null) { - mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); - } - if (mRecents != null) { - mRecents.addRecentEmoji(rootView.getContext(), emojicon); - } - } - }); - gridView.setAdapter(mAdapter); - } - - private void setRecents(EmojiconRecents recents) { + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); + mEmojiconPopup = emojiconPopup; + rootView = inflater.inflate(R.layout.emojicon_grid, null); + setRecents(recents); + GridView gridView = (GridView) rootView.findViewById(R.id.Emoji_GridView); + if (emojicons == null) { + mData = People.DATA; + } else { + Object[] o = (Object[]) emojicons; + mData = Arrays.asList(o).toArray(new Emojicon[o.length]); + } + EmojiAdapter mAdapter = new EmojiAdapter(rootView.getContext(), mData); + mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { + + @Override + public void onEmojiconClicked(Emojicon emojicon) { + if (mEmojiconPopup.onEmojiconClickedListener != null) { + mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); + } + if (mRecents != null) { + mRecents.addRecentEmoji(rootView.getContext(), emojicon); + } + } + }); + gridView.setAdapter(mAdapter); + } + + private void setRecents(EmojiconRecents recents) { mRecents = recents; } public interface OnEmojiconClickedListener { void onEmojiconClicked(Emojicon emojicon); } - + } diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java index 8fac5385b..b9c214bad 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java @@ -1394,7 +1394,7 @@ public final class EmojiconHandler { public static void addEmojis(Context context, Spannable text, int emojiSize, int index, int length) { int textLength = text.length(); int textLengthToProcessMax = textLength - index; - int textLengthToProcess = length < 0 || length >= textLengthToProcessMax ? textLength : (length+index); + int textLengthToProcess = length < 0 || length >= textLengthToProcessMax ? textLength : (length + index); // remove spans throughout all text EmojiconSpan[] oldSpans = text.getSpans(0, textLength, EmojiconSpan.class); diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecents.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecents.java index c7a90c837..e3274ed77 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecents.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecents.java @@ -21,8 +21,8 @@ import android.content.Context; import github.ankushsachdeva.emojicon.emoji.Emojicon; /** -* @author Daniele Ricci -*/ + * @author Daniele Ricci + */ public interface EmojiconRecents { public void addRecentEmoji(Context context, Emojicon emojicon); } diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java index d4f2211e7..c07ba082d 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsGridView.java @@ -23,26 +23,26 @@ import github.ankushsachdeva.emojicon.emoji.Emojicon; /** * @author Daniele Ricci - * @author Ankush Sachdeva (sankush@yahoo.co.in) + * @author Ankush Sachdeva (sankush@yahoo.co.in) */ public class EmojiconRecentsGridView extends EmojiconGridView implements EmojiconRecents { - EmojiAdapter mAdapter; - - public EmojiconRecentsGridView(Context context, Emojicon[] emojicons, - EmojiconRecents recents,EmojiconsPopup emojiconsPopup) { - super(context, emojicons, recents, emojiconsPopup); - EmojiconRecentsManager recents1 = EmojiconRecentsManager - .getInstance(rootView.getContext()); - mAdapter = new EmojiAdapter(rootView.getContext(), recents1); - mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { - - @Override - public void onEmojiconClicked(Emojicon emojicon) { - if (mEmojiconPopup.onEmojiconClickedListener != null) { - mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); - } - } - }); + EmojiAdapter mAdapter; + + public EmojiconRecentsGridView(Context context, Emojicon[] emojicons, + EmojiconRecents recents, EmojiconsPopup emojiconsPopup) { + super(context, emojicons, recents, emojiconsPopup); + EmojiconRecentsManager recents1 = EmojiconRecentsManager + .getInstance(rootView.getContext()); + mAdapter = new EmojiAdapter(rootView.getContext(), recents1); + mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { + + @Override + public void onEmojiconClicked(Emojicon emojicon) { + if (mEmojiconPopup.onEmojiconClickedListener != null) { + mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); + } + } + }); GridView gridView = (GridView) rootView.findViewById(R.id.Emoji_GridView); gridView.setAdapter(mAdapter); } @@ -50,7 +50,7 @@ public class EmojiconRecentsGridView extends EmojiconGridView implements Emojico @Override public void addRecentEmoji(Context context, Emojicon emojicon) { EmojiconRecentsManager recents = EmojiconRecentsManager - .getInstance(context); + .getInstance(context); recents.push(emojicon); // notify dataset changed diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java index 177f11591..f208b10c4 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconRecentsManager.java @@ -26,8 +26,8 @@ import github.ankushsachdeva.emojicon.emoji.Emojicon; /** -* @author Daniele Ricci -*/ + * @author Daniele Ricci + */ public class EmojiconRecentsManager extends ArrayList<Emojicon> { private static final String PREFERENCE_NAME = "emojicon"; @@ -88,7 +88,7 @@ public class EmojiconRecentsManager extends ArrayList<Emojicon> { boolean ret = super.remove(object); return ret; } - + private SharedPreferences getPreferences() { return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); } @@ -99,14 +99,13 @@ public class EmojiconRecentsManager extends ArrayList<Emojicon> { StringTokenizer tokenizer = new StringTokenizer(str, "~"); while (tokenizer.hasMoreTokens()) { try { - add(new Emojicon(tokenizer.nextToken())); - } - catch (NumberFormatException e) { + add(new Emojicon(tokenizer.nextToken())); + } catch (NumberFormatException e) { // ignored } } } - + public void saveRecents() { StringBuilder str = new StringBuilder(); int c = size(); diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconsPopup.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconsPopup.java index 2a35aa9c0..f7d68ddc5 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconsPopup.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconsPopup.java @@ -53,372 +53,376 @@ import github.ankushsachdeva.emojicon.emoji.Symbols; */ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChangeListener, EmojiconRecents { - private int mEmojiTabLastSelectedIndex = -1; - private View[] mEmojiTabs; - private PagerAdapter mEmojisAdapter; - private EmojiconRecentsManager mRecentsManager; - private int keyBoardHeight = 0; - private Boolean pendingOpen = false; - private Boolean isOpened = false; - OnEmojiconClickedListener onEmojiconClickedListener; - OnEmojiconBackspaceClickedListener onEmojiconBackspaceClickedListener; - OnSoftKeyboardOpenCloseListener onSoftKeyboardOpenCloseListener; - View rootView; - Context mContext; - - private ViewPager emojisPager; - /** - * Constructor - * @param rootView The top most layout in your view hierarchy. The difference of this view and the screen height will be used to calculate the keyboard height. - * @param mContext The context of current activity. - */ - public EmojiconsPopup(View rootView, Context mContext){ - super(mContext); - this.mContext = mContext; - this.rootView = rootView; - View customView = createCustomView(); - setContentView(customView); - setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); - //default size - setSize((int) mContext.getResources().getDimension(R.dimen.keyboard_height), LayoutParams.MATCH_PARENT); - } - /** - * Set the listener for the event of keyboard opening or closing. - */ - public void setOnSoftKeyboardOpenCloseListener(OnSoftKeyboardOpenCloseListener listener){ - this.onSoftKeyboardOpenCloseListener = listener; - } - - /** - * Set the listener for the event when any of the emojicon is clicked - */ - public void setOnEmojiconClickedListener(OnEmojiconClickedListener listener){ - this.onEmojiconClickedListener = listener; - } - - /** - * Set the listener for the event when backspace on emojicon popup is clicked - */ - public void setOnEmojiconBackspaceClickedListener(OnEmojiconBackspaceClickedListener listener){ - this.onEmojiconBackspaceClickedListener = listener; - } - - /** - * Use this function to show the emoji popup. - * NOTE: Since, the soft keyboard sizes are variable on different android devices, the - * library needs you to open the soft keyboard atleast once before calling this function. - * If that is not possible see showAtBottomPending() function. - * - */ - public void showAtBottom(){ - showAtLocation(rootView, Gravity.BOTTOM, 0, 0); - } - /** - * Use this function when the soft keyboard has not been opened yet. This - * will show the emoji popup after the keyboard is up next time. - * Generally, you will be calling InputMethodManager.showSoftInput function after - * calling this function. - */ - public void showAtBottomPending(){ - if(isKeyBoardOpen()) - showAtBottom(); - else - pendingOpen = true; - } - - /** - * - * @return Returns true if the soft keyboard is open, false otherwise. - */ - public Boolean isKeyBoardOpen(){ - return isOpened; - } - - /** - * Dismiss the popup - */ - @Override - public void dismiss() { - super.dismiss(); - EmojiconRecentsManager - .getInstance(mContext).saveRecents(); - } - - /** - * Call this function to resize the emoji popup according to your soft keyboard size - */ - public void setSizeForSoftKeyboard(){ - rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - Rect r = new Rect(); - rootView.getWindowVisibleDisplayFrame(r); - - int screenHeight = getUsableScreenHeight(); - int heightDifference = screenHeight - - (r.bottom - r.top); - int resourceId = mContext.getResources() - .getIdentifier("status_bar_height", - "dimen", "android"); - if (resourceId > 0) { - heightDifference -= mContext.getResources() - .getDimensionPixelSize(resourceId); - } - if (heightDifference > 100) { - keyBoardHeight = heightDifference; - setSize(LayoutParams.MATCH_PARENT, keyBoardHeight); - if(isOpened == false){ - if(onSoftKeyboardOpenCloseListener!=null) - onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight); - } - isOpened = true; - if(pendingOpen){ - showAtBottom(); - pendingOpen = false; - } - } - else{ - isOpened = false; - if(onSoftKeyboardOpenCloseListener!=null) - onSoftKeyboardOpenCloseListener.onKeyboardClose(); - } - } - }); - } - - private int getUsableScreenHeight() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - DisplayMetrics metrics = new DisplayMetrics(); - - WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); - windowManager.getDefaultDisplay().getMetrics(metrics); - - return metrics.heightPixels; - - } else { - return rootView.getRootView().getHeight(); - } - } - - /** - * Manually set the popup window size - * @param width Width of the popup - * @param height Height of the popup - */ - public void setSize(int width, int height){ - setWidth(width); - setHeight(height); - } - - private View createCustomView() { - LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(R.layout.emojicons, null, false); - emojisPager = (ViewPager) view.findViewById(R.id.emojis_pager); - emojisPager.setOnPageChangeListener(this); - EmojiconRecents recents = this; - mEmojisAdapter = new EmojisPagerAdapter( - Arrays.asList( - new EmojiconRecentsGridView(mContext, null, null, this), - new EmojiconGridView(mContext, People.DATA, recents, this), - new EmojiconGridView(mContext, Nature.DATA, recents, this), - new EmojiconGridView(mContext, Objects.DATA, recents, this), - new EmojiconGridView(mContext, Places.DATA, recents, this), - new EmojiconGridView(mContext, Symbols.DATA, recents, this) - ) - ); - emojisPager.setAdapter(mEmojisAdapter); - mEmojiTabs = new View[6]; - mEmojiTabs[0] = view.findViewById(R.id.emojis_tab_0_recents); - mEmojiTabs[1] = view.findViewById(R.id.emojis_tab_1_people); - mEmojiTabs[2] = view.findViewById(R.id.emojis_tab_2_nature); - mEmojiTabs[3] = view.findViewById(R.id.emojis_tab_3_objects); - mEmojiTabs[4] = view.findViewById(R.id.emojis_tab_4_cars); - mEmojiTabs[5] = view.findViewById(R.id.emojis_tab_5_punctuation); - for (int i = 0; i < mEmojiTabs.length; i++) { - final int position = i; - mEmojiTabs[i].setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - emojisPager.setCurrentItem(position); - } - }); - } - view.findViewById(R.id.emojis_backspace).setOnTouchListener(new RepeatListener(1000, 50, new OnClickListener() { - - @Override - public void onClick(View v) { - if(onEmojiconBackspaceClickedListener != null) - onEmojiconBackspaceClickedListener.onEmojiconBackspaceClicked(v); - } - })); - - // get last selected page - mRecentsManager = EmojiconRecentsManager.getInstance(view.getContext()); - int page = mRecentsManager.getRecentPage(); - // last page was recents, check if there are recents to use - // if none was found, go to page 1 - if (page == 0 && mRecentsManager.size() == 0) { - page = 1; - } - - if (page == 0) { - onPageSelected(page); - } - else { - emojisPager.setCurrentItem(page, false); - } - return view; - } - - @Override - public void addRecentEmoji(Context context, Emojicon emojicon) { - EmojiconRecentsGridView fragment = ((EmojisPagerAdapter)emojisPager.getAdapter()).getRecentFragment(); - fragment.addRecentEmoji(context, emojicon); - } - - - @Override - public void onPageScrolled(int i, float v, int i2) { - } - - @Override - public void onPageSelected(int i) { - if (mEmojiTabLastSelectedIndex == i) { - return; - } - switch (i) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - if (mEmojiTabLastSelectedIndex >= 0 && mEmojiTabLastSelectedIndex < mEmojiTabs.length) { - mEmojiTabs[mEmojiTabLastSelectedIndex].setSelected(false); - } - mEmojiTabs[i].setSelected(true); - mEmojiTabLastSelectedIndex = i; - mRecentsManager.setRecentPage(i); - break; - } - } - - @Override - public void onPageScrollStateChanged(int i) { - } - - private static class EmojisPagerAdapter extends PagerAdapter { - private List<EmojiconGridView> views; - public EmojiconRecentsGridView getRecentFragment(){ - for (EmojiconGridView it : views) { - if(it instanceof EmojiconRecentsGridView) - return (EmojiconRecentsGridView)it; - } - return null; - } - public EmojisPagerAdapter(List<EmojiconGridView> views) { - super(); - this.views = views; - } - - @Override - public int getCount() { - return views.size(); - } - - - @Override - public Object instantiateItem(ViewGroup container, int position) { - View v = views.get(position).rootView; - ((ViewPager)container).addView(v, 0); - return v; - } - - @Override - public void destroyItem(ViewGroup container, int position, Object view) { - ((ViewPager)container).removeView((View)view); - } - - @Override - public boolean isViewFromObject(View view, Object key) { - return key == view; - } - } - - /** - * A class, that can be used as a TouchListener on any view (e.g. a Button). - * It cyclically runs a clickListener, emulating keyboard-like behaviour. First - * click is fired immediately, next before initialInterval, and subsequent before - * normalInterval. - * <p/> - * <p>Interval is scheduled before the onClick completes, so it has to run fast. - * If it runs slow, it does not generate skipped onClicks. - */ - public static class RepeatListener implements View.OnTouchListener { - - private Handler handler = new Handler(); - - private int initialInterval; - private final int normalInterval; - private final View.OnClickListener clickListener; - - private Runnable handlerRunnable = new Runnable() { - @Override - public void run() { - if (downView == null) { - return; - } - handler.removeCallbacksAndMessages(downView); - handler.postAtTime(this, downView, SystemClock.uptimeMillis() + normalInterval); - clickListener.onClick(downView); - } - }; - - private View downView; - - /** - * @param initialInterval The interval before first click event - * @param normalInterval The interval before second and subsequent click - * events - * @param clickListener The OnClickListener, that will be called - * periodically - */ - public RepeatListener(int initialInterval, int normalInterval, View.OnClickListener clickListener) { - if (clickListener == null) - throw new IllegalArgumentException("null runnable"); - if (initialInterval < 0 || normalInterval < 0) - throw new IllegalArgumentException("negative interval"); - - this.initialInterval = initialInterval; - this.normalInterval = normalInterval; - this.clickListener = clickListener; - } - - public boolean onTouch(View view, MotionEvent motionEvent) { - switch (motionEvent.getAction()) { - case MotionEvent.ACTION_DOWN: - downView = view; - handler.removeCallbacks(handlerRunnable); - handler.postAtTime(handlerRunnable, downView, SystemClock.uptimeMillis() + initialInterval); - clickListener.onClick(view); - return true; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_OUTSIDE: - handler.removeCallbacksAndMessages(downView); - downView = null; - return true; - } - return false; - } - } - - public interface OnEmojiconBackspaceClickedListener { - void onEmojiconBackspaceClicked(View v); - } - - public interface OnSoftKeyboardOpenCloseListener{ - void onKeyboardOpen(int keyBoardHeight); - void onKeyboardClose(); - } + private int mEmojiTabLastSelectedIndex = -1; + private View[] mEmojiTabs; + private PagerAdapter mEmojisAdapter; + private EmojiconRecentsManager mRecentsManager; + private int keyBoardHeight = 0; + private Boolean pendingOpen = false; + private Boolean isOpened = false; + OnEmojiconClickedListener onEmojiconClickedListener; + OnEmojiconBackspaceClickedListener onEmojiconBackspaceClickedListener; + OnSoftKeyboardOpenCloseListener onSoftKeyboardOpenCloseListener; + View rootView; + Context mContext; + + private ViewPager emojisPager; + + /** + * Constructor + * + * @param rootView The top most layout in your view hierarchy. The difference of this view and the screen height will be used to calculate the keyboard height. + * @param mContext The context of current activity. + */ + public EmojiconsPopup(View rootView, Context mContext) { + super(mContext); + this.mContext = mContext; + this.rootView = rootView; + View customView = createCustomView(); + setContentView(customView); + setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + //default size + setSize((int) mContext.getResources().getDimension(R.dimen.keyboard_height), LayoutParams.MATCH_PARENT); + } + + /** + * Set the listener for the event of keyboard opening or closing. + */ + public void setOnSoftKeyboardOpenCloseListener(OnSoftKeyboardOpenCloseListener listener) { + this.onSoftKeyboardOpenCloseListener = listener; + } + + /** + * Set the listener for the event when any of the emojicon is clicked + */ + public void setOnEmojiconClickedListener(OnEmojiconClickedListener listener) { + this.onEmojiconClickedListener = listener; + } + + /** + * Set the listener for the event when backspace on emojicon popup is clicked + */ + public void setOnEmojiconBackspaceClickedListener(OnEmojiconBackspaceClickedListener listener) { + this.onEmojiconBackspaceClickedListener = listener; + } + + /** + * Use this function to show the emoji popup. + * NOTE: Since, the soft keyboard sizes are variable on different android devices, the + * library needs you to open the soft keyboard atleast once before calling this function. + * If that is not possible see showAtBottomPending() function. + */ + public void showAtBottom() { + showAtLocation(rootView, Gravity.BOTTOM, 0, 0); + } + + /** + * Use this function when the soft keyboard has not been opened yet. This + * will show the emoji popup after the keyboard is up next time. + * Generally, you will be calling InputMethodManager.showSoftInput function after + * calling this function. + */ + public void showAtBottomPending() { + if (isKeyBoardOpen()) + showAtBottom(); + else + pendingOpen = true; + } + + /** + * @return Returns true if the soft keyboard is open, false otherwise. + */ + public Boolean isKeyBoardOpen() { + return isOpened; + } + + /** + * Dismiss the popup + */ + @Override + public void dismiss() { + super.dismiss(); + EmojiconRecentsManager + .getInstance(mContext).saveRecents(); + } + + /** + * Call this function to resize the emoji popup according to your soft keyboard size + */ + public void setSizeForSoftKeyboard() { + rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + Rect r = new Rect(); + rootView.getWindowVisibleDisplayFrame(r); + + int screenHeight = getUsableScreenHeight(); + int heightDifference = screenHeight + - (r.bottom - r.top); + int resourceId = mContext.getResources() + .getIdentifier("status_bar_height", + "dimen", "android"); + if (resourceId > 0) { + heightDifference -= mContext.getResources() + .getDimensionPixelSize(resourceId); + } + if (heightDifference > 100) { + keyBoardHeight = heightDifference; + setSize(LayoutParams.MATCH_PARENT, keyBoardHeight); + if (isOpened == false) { + if (onSoftKeyboardOpenCloseListener != null) + onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight); + } + isOpened = true; + if (pendingOpen) { + showAtBottom(); + pendingOpen = false; + } + } else { + isOpened = false; + if (onSoftKeyboardOpenCloseListener != null) + onSoftKeyboardOpenCloseListener.onKeyboardClose(); + } + } + }); + } + + private int getUsableScreenHeight() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + DisplayMetrics metrics = new DisplayMetrics(); + + WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); + windowManager.getDefaultDisplay().getMetrics(metrics); + + return metrics.heightPixels; + + } else { + return rootView.getRootView().getHeight(); + } + } + + /** + * Manually set the popup window size + * + * @param width Width of the popup + * @param height Height of the popup + */ + public void setSize(int width, int height) { + setWidth(width); + setHeight(height); + } + + private View createCustomView() { + LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.emojicons, null, false); + emojisPager = (ViewPager) view.findViewById(R.id.emojis_pager); + emojisPager.setOnPageChangeListener(this); + EmojiconRecents recents = this; + mEmojisAdapter = new EmojisPagerAdapter( + Arrays.asList( + new EmojiconRecentsGridView(mContext, null, null, this), + new EmojiconGridView(mContext, People.DATA, recents, this), + new EmojiconGridView(mContext, Nature.DATA, recents, this), + new EmojiconGridView(mContext, Objects.DATA, recents, this), + new EmojiconGridView(mContext, Places.DATA, recents, this), + new EmojiconGridView(mContext, Symbols.DATA, recents, this) + ) + ); + emojisPager.setAdapter(mEmojisAdapter); + mEmojiTabs = new View[6]; + mEmojiTabs[0] = view.findViewById(R.id.emojis_tab_0_recents); + mEmojiTabs[1] = view.findViewById(R.id.emojis_tab_1_people); + mEmojiTabs[2] = view.findViewById(R.id.emojis_tab_2_nature); + mEmojiTabs[3] = view.findViewById(R.id.emojis_tab_3_objects); + mEmojiTabs[4] = view.findViewById(R.id.emojis_tab_4_cars); + mEmojiTabs[5] = view.findViewById(R.id.emojis_tab_5_punctuation); + for (int i = 0; i < mEmojiTabs.length; i++) { + final int position = i; + mEmojiTabs[i].setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + emojisPager.setCurrentItem(position); + } + }); + } + view.findViewById(R.id.emojis_backspace).setOnTouchListener(new RepeatListener(1000, 50, new OnClickListener() { + + @Override + public void onClick(View v) { + if (onEmojiconBackspaceClickedListener != null) + onEmojiconBackspaceClickedListener.onEmojiconBackspaceClicked(v); + } + })); + + // get last selected page + mRecentsManager = EmojiconRecentsManager.getInstance(view.getContext()); + int page = mRecentsManager.getRecentPage(); + // last page was recents, check if there are recents to use + // if none was found, go to page 1 + if (page == 0 && mRecentsManager.size() == 0) { + page = 1; + } + + if (page == 0) { + onPageSelected(page); + } else { + emojisPager.setCurrentItem(page, false); + } + return view; + } + + @Override + public void addRecentEmoji(Context context, Emojicon emojicon) { + EmojiconRecentsGridView fragment = ((EmojisPagerAdapter) emojisPager.getAdapter()).getRecentFragment(); + fragment.addRecentEmoji(context, emojicon); + } + + + @Override + public void onPageScrolled(int i, float v, int i2) { + } + + @Override + public void onPageSelected(int i) { + if (mEmojiTabLastSelectedIndex == i) { + return; + } + switch (i) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + if (mEmojiTabLastSelectedIndex >= 0 && mEmojiTabLastSelectedIndex < mEmojiTabs.length) { + mEmojiTabs[mEmojiTabLastSelectedIndex].setSelected(false); + } + mEmojiTabs[i].setSelected(true); + mEmojiTabLastSelectedIndex = i; + mRecentsManager.setRecentPage(i); + break; + } + } + + @Override + public void onPageScrollStateChanged(int i) { + } + + private static class EmojisPagerAdapter extends PagerAdapter { + private List<EmojiconGridView> views; + + public EmojiconRecentsGridView getRecentFragment() { + for (EmojiconGridView it : views) { + if (it instanceof EmojiconRecentsGridView) + return (EmojiconRecentsGridView) it; + } + return null; + } + + public EmojisPagerAdapter(List<EmojiconGridView> views) { + super(); + this.views = views; + } + + @Override + public int getCount() { + return views.size(); + } + + + @Override + public Object instantiateItem(ViewGroup container, int position) { + View v = views.get(position).rootView; + ((ViewPager) container).addView(v, 0); + return v; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object view) { + ((ViewPager) container).removeView((View) view); + } + + @Override + public boolean isViewFromObject(View view, Object key) { + return key == view; + } + } + + /** + * A class, that can be used as a TouchListener on any view (e.g. a Button). + * It cyclically runs a clickListener, emulating keyboard-like behaviour. First + * click is fired immediately, next before initialInterval, and subsequent before + * normalInterval. + * <p/> + * <p>Interval is scheduled before the onClick completes, so it has to run fast. + * If it runs slow, it does not generate skipped onClicks. + */ + public static class RepeatListener implements View.OnTouchListener { + + private Handler handler = new Handler(); + + private int initialInterval; + private final int normalInterval; + private final View.OnClickListener clickListener; + + private Runnable handlerRunnable = new Runnable() { + @Override + public void run() { + if (downView == null) { + return; + } + handler.removeCallbacksAndMessages(downView); + handler.postAtTime(this, downView, SystemClock.uptimeMillis() + normalInterval); + clickListener.onClick(downView); + } + }; + + private View downView; + + /** + * @param initialInterval The interval before first click event + * @param normalInterval The interval before second and subsequent click + * events + * @param clickListener The OnClickListener, that will be called + * periodically + */ + public RepeatListener(int initialInterval, int normalInterval, View.OnClickListener clickListener) { + if (clickListener == null) + throw new IllegalArgumentException("null runnable"); + if (initialInterval < 0 || normalInterval < 0) + throw new IllegalArgumentException("negative interval"); + + this.initialInterval = initialInterval; + this.normalInterval = normalInterval; + this.clickListener = clickListener; + } + + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + downView = view; + handler.removeCallbacks(handlerRunnable); + handler.postAtTime(handlerRunnable, downView, SystemClock.uptimeMillis() + initialInterval); + clickListener.onClick(view); + return true; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_OUTSIDE: + handler.removeCallbacksAndMessages(downView); + downView = null; + return true; + } + return false; + } + } + + public interface OnEmojiconBackspaceClickedListener { + void onEmojiconBackspaceClicked(View v); + } + + public interface OnSoftKeyboardOpenCloseListener { + void onKeyboardOpen(int keyBoardHeight); + + void onKeyboardClose(); + } } diff --git a/libs/emojicon/src/main/res/drawable/ic_emoji_nature_light.xml b/libs/emojicon/src/main/res/drawable/ic_emoji_nature_light.xml index 543409e03..87464fb1e 100644 --- a/libs/emojicon/src/main/res/drawable/ic_emoji_nature_light.xml +++ b/libs/emojicon/src/main/res/drawable/ic_emoji_nature_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,15 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_nature_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_nature_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_nature_light_activated" /> - <item - android:drawable="@drawable/ic_emoji_nature_light_normal" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_nature_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_nature_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_nature_light_activated" /> + <item android:drawable="@drawable/ic_emoji_nature_light_normal" /> </selector> diff --git a/libs/emojicon/src/main/res/drawable/ic_emoji_objects_light.xml b/libs/emojicon/src/main/res/drawable/ic_emoji_objects_light.xml index 4096e695b..74c80e3d0 100644 --- a/libs/emojicon/src/main/res/drawable/ic_emoji_objects_light.xml +++ b/libs/emojicon/src/main/res/drawable/ic_emoji_objects_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_objects_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_objects_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_objects_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_objects_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_objects_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_objects_light_activated" /> <item android:drawable="@drawable/ic_emoji_objects_light_normal" /> </selector> diff --git a/libs/emojicon/src/main/res/drawable/ic_emoji_people_light.xml b/libs/emojicon/src/main/res/drawable/ic_emoji_people_light.xml index ea9e406a4..06f7aebbf 100644 --- a/libs/emojicon/src/main/res/drawable/ic_emoji_people_light.xml +++ b/libs/emojicon/src/main/res/drawable/ic_emoji_people_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_people_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_people_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_people_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_people_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_people_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_people_light_activated" /> <item android:drawable="@drawable/ic_emoji_people_light_normal" /> </selector> diff --git a/libs/emojicon/src/main/res/drawable/ic_emoji_places_light.xml b/libs/emojicon/src/main/res/drawable/ic_emoji_places_light.xml index 312cad9c3..36f258876 100644 --- a/libs/emojicon/src/main/res/drawable/ic_emoji_places_light.xml +++ b/libs/emojicon/src/main/res/drawable/ic_emoji_places_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_places_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_places_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_places_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_places_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_places_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_places_light_activated" /> <item android:drawable="@drawable/ic_emoji_places_light_normal" /> </selector> diff --git a/libs/emojicon/src/main/res/drawable/ic_emoji_recent_light.xml b/libs/emojicon/src/main/res/drawable/ic_emoji_recent_light.xml index 8c2123f83..90f2c8565 100644 --- a/libs/emojicon/src/main/res/drawable/ic_emoji_recent_light.xml +++ b/libs/emojicon/src/main/res/drawable/ic_emoji_recent_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_recent_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_recent_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_recent_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_recent_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_recent_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_recent_light_activated" /> <item android:drawable="@drawable/ic_emoji_recent_light_normal" /> </selector> diff --git a/libs/emojicon/src/main/res/drawable/ic_emoji_symbols_light.xml b/libs/emojicon/src/main/res/drawable/ic_emoji_symbols_light.xml index 79aaf0fc5..9077c3289 100644 --- a/libs/emojicon/src/main/res/drawable/ic_emoji_symbols_light.xml +++ b/libs/emojicon/src/main/res/drawable/ic_emoji_symbols_light.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- /* ** ** Copyright 2013, The Android Open Source Project @@ -19,14 +18,8 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:state_focused="true" - android:drawable="@drawable/ic_emoji_symbols_light_activated" /> - <item - android:state_pressed="true" - android:drawable="@drawable/ic_emoji_symbols_light_activated" /> - <item - android:state_selected="true" - android:drawable="@drawable/ic_emoji_symbols_light_activated" /> + <item android:state_focused="true" android:drawable="@drawable/ic_emoji_symbols_light_activated" /> + <item android:state_pressed="true" android:drawable="@drawable/ic_emoji_symbols_light_activated" /> + <item android:state_selected="true" android:drawable="@drawable/ic_emoji_symbols_light_activated" /> <item android:drawable="@drawable/ic_emoji_symbols_light_normal" /> </selector> diff --git a/libs/emojicon/src/main/res/drawable/orca_composer_attach_camera_button.xml b/libs/emojicon/src/main/res/drawable/orca_composer_attach_camera_button.xml index 0b255fb27..56e8d0484 100644 --- a/libs/emojicon/src/main/res/drawable/orca_composer_attach_camera_button.xml +++ b/libs/emojicon/src/main/res/drawable/orca_composer_attach_camera_button.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_attach_camera_pressed" /> <item android:drawable="@drawable/orca_attach_camera_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/drawable/orca_composer_attach_location_button.xml b/libs/emojicon/src/main/res/drawable/orca_composer_attach_location_button.xml index 4971113aa..be898ebcf 100644 --- a/libs/emojicon/src/main/res/drawable/orca_composer_attach_location_button.xml +++ b/libs/emojicon/src/main/res/drawable/orca_composer_attach_location_button.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2013 Klamr. All rights reserved. ~ ~ This software is the confidential and proprietary information of Klamr or one of its @@ -14,8 +13,7 @@ ~ ITS DERIVATIVES. --> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_pressed="true" android:drawable="@drawable/orca_attach_location_pressed"/> - <item android:drawable="@drawable/orca_attach_location_normal"/> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_pressed="true" android:drawable="@drawable/orca_attach_location_pressed" /> + <item android:drawable="@drawable/orca_attach_location_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/drawable/orca_composer_attach_photo_button.xml b/libs/emojicon/src/main/res/drawable/orca_composer_attach_photo_button.xml index ca7508dd9..21f8e8e6c 100644 --- a/libs/emojicon/src/main/res/drawable/orca_composer_attach_photo_button.xml +++ b/libs/emojicon/src/main/res/drawable/orca_composer_attach_photo_button.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_attach_photo_pressed" /> <item android:drawable="@drawable/orca_attach_photo_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/drawable/orca_composer_popup_button.xml b/libs/emojicon/src/main/res/drawable/orca_composer_popup_button.xml index d43dc26e4..dccfb4848 100644 --- a/libs/emojicon/src/main/res/drawable/orca_composer_popup_button.xml +++ b/libs/emojicon/src/main/res/drawable/orca_composer_popup_button.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_popup_pressed" /> <item android:drawable="@drawable/orca_composer_popup_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/drawable/orca_composer_popup_button_active.xml b/libs/emojicon/src/main/res/drawable/orca_composer_popup_button_active.xml index f5e40ef8c..556d0151b 100644 --- a/libs/emojicon/src/main/res/drawable/orca_composer_popup_button_active.xml +++ b/libs/emojicon/src/main/res/drawable/orca_composer_popup_button_active.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_popup_active_pressed" /> <item android:drawable="@drawable/orca_composer_popup_active_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/drawable/orca_emoji_backspace_front_button.xml b/libs/emojicon/src/main/res/drawable/orca_emoji_backspace_front_button.xml index a2d2f5b62..e922eb686 100644 --- a/libs/emojicon/src/main/res/drawable/orca_emoji_backspace_front_button.xml +++ b/libs/emojicon/src/main/res/drawable/orca_emoji_backspace_front_button.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_backspace_front_pressed"/> - <item android:drawable="@drawable/orca_emoji_backspace_front_normal"/> + <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_backspace_front_pressed" /> + <item android:drawable="@drawable/orca_emoji_backspace_front_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/drawable/orca_emoji_more_front_button.xml b/libs/emojicon/src/main/res/drawable/orca_emoji_more_front_button.xml index a799d56d9..3e0e9f6f0 100644 --- a/libs/emojicon/src/main/res/drawable/orca_emoji_more_front_button.xml +++ b/libs/emojicon/src/main/res/drawable/orca_emoji_more_front_button.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_more_front_pressed"/> - <item android:drawable="@drawable/orca_emoji_more_front_normal"/> + <item android:state_pressed="true" android:drawable="@drawable/orca_emoji_more_front_pressed" /> + <item android:drawable="@drawable/orca_emoji_more_front_normal" /> </selector>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/drawable/orca_emoji_tab_background.xml b/libs/emojicon/src/main/res/drawable/orca_emoji_tab_background.xml index f68e6212b..d597dc03a 100644 --- a/libs/emojicon/src/main/res/drawable/orca_emoji_tab_background.xml +++ b/libs/emojicon/src/main/res/drawable/orca_emoji_tab_background.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/orca_composer_tab_pressed" /> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_tab_active" /> <item android:drawable="@drawable/orca_composer_tab" /> diff --git a/libs/emojicon/src/main/res/drawable/orca_emoji_tab_dark_background.xml b/libs/emojicon/src/main/res/drawable/orca_emoji_tab_dark_background.xml index 07ff608c9..f0b0d1a66 100644 --- a/libs/emojicon/src/main/res/drawable/orca_emoji_tab_dark_background.xml +++ b/libs/emojicon/src/main/res/drawable/orca_emoji_tab_dark_background.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2013 Klamr. All rights reserved. ~ ~ This software is the confidential and proprietary information of Klamr or one of its @@ -14,8 +13,7 @@ ~ ITS DERIVATIVES. --> -<selector - xmlns:android="http://schemas.android.com/apk/res/android"> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/orca_composer_tab_pressed" /> <item android:drawable="@drawable/orca_composer_tab_active" android:state_checked="true" /> <item android:drawable="@drawable/orca_composer_tab_dark" /> diff --git a/libs/emojicon/src/main/res/layout/emojicon_grid.xml b/libs/emojicon/src/main/res/layout/emojicon_grid.xml index 457f8756b..7e1579c3f 100644 --- a/libs/emojicon/src/main/res/layout/emojicon_grid.xml +++ b/libs/emojicon/src/main/res/layout/emojicon_grid.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2013 Klamr. All rights reserved. ~ ~ This software is the confidential and proprietary information of Klamr or one of its diff --git a/libs/emojicon/src/main/res/layout/emojicon_item.xml b/libs/emojicon/src/main/res/layout/emojicon_item.xml index ed11041a7..a85b1b640 100644 --- a/libs/emojicon/src/main/res/layout/emojicon_item.xml +++ b/libs/emojicon/src/main/res/layout/emojicon_item.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright 2014 Ankush Sachdeva ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,18 +14,18 @@ ~ limitations under the License. --> -<FrameLayout - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:emojicon="http://schemas.android.com/apk/res-auto" - android:layout_width="wrap_content" - android:layout_height="wrap_content"> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:emojicon="http://schemas.android.com/apk/res-auto" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + <github.ankushsachdeva.emojicon.EmojiconTextView - android:layout_gravity="center" - android:id="@+id/emojicon_icon" - android:layout_width="36dip" - android:layout_height="36dip" - emojicon:emojiconSize="30dip" - android:focusable="false" - android:focusableInTouchMode="false" - android:gravity="center"/> + android:layout_gravity="center" + android:id="@+id/emojicon_icon" + android:layout_width="36dip" + android:layout_height="36dip" + emojicon:emojiconSize="30dip" + android:focusable="false" + android:focusableInTouchMode="false" + android:gravity="center" /> </FrameLayout>
\ No newline at end of file diff --git a/libs/emojicon/src/main/res/layout/emojicons.xml b/libs/emojicon/src/main/res/layout/emojicons.xml index 287923d1b..e61c2fb34 100644 --- a/libs/emojicon/src/main/res/layout/emojicons.xml +++ b/libs/emojicon/src/main/res/layout/emojicons.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright 2014 Ankush Sachdeva ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,104 +15,120 @@ --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:background="@drawable/keyboard_background_holo" - android:layout_width="match_parent" - android:layout_height="match_parent"> + android:background="@drawable/keyboard_background_holo" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <LinearLayout - android:id="@+id/emojis_tab" - android:layout_width="match_parent" - android:layout_height="50dip" - android:layout_alignParentTop="true" - android:orientation="horizontal"> + android:id="@+id/emojis_tab" + android:layout_width="match_parent" + android:layout_height="50dip" + android:layout_alignParentTop="true" + android:orientation="horizontal"> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_0_recents" - android:src="@drawable/ic_emoji_recent_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_0_recents" + android:src="@drawable/ic_emoji_recent_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_1_people" - android:src="@drawable/ic_emoji_people_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_1_people" + android:src="@drawable/ic_emoji_people_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_2_nature" - android:src="@drawable/ic_emoji_nature_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_2_nature" + android:src="@drawable/ic_emoji_nature_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_3_objects" - android:src="@drawable/ic_emoji_objects_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_3_objects" + android:src="@drawable/ic_emoji_objects_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_4_cars" - android:src="@drawable/ic_emoji_places_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_4_cars" + android:src="@drawable/ic_emoji_places_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:scaleType="center" - android:id="@+id/emojis_tab_5_punctuation" - android:src="@drawable/ic_emoji_symbols_light"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:scaleType="center" + android:id="@+id/emojis_tab_5_punctuation" + android:src="@drawable/ic_emoji_symbols_light" /> + <View - android:layout_width="1px" - android:layout_height="match_parent" - android:background="#888888"/> + android:layout_width="1px" + android:layout_height="match_parent" + android:background="#888888" /> + <ImageButton - android:background="@null" - android:layout_width="0dip" - android:layout_height="match_parent" - android:layout_weight="1" - android:id="@+id/emojis_backspace" - android:src="@drawable/sym_keyboard_delete_holo_dark"/> + android:background="@null" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" + android:id="@+id/emojis_backspace" + android:src="@drawable/sym_keyboard_delete_holo_dark" /> </LinearLayout> + <android.support.v4.view.ViewPager android:layout_below="@id/emojis_tab" android:id="@+id/emojis_pager" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentBottom="true"/> + android:layout_alignParentBottom="true" /> + <View android:layout_width="match_parent" android:layout_height="1px" android:layout_below="@id/emojis_tab" - android:background="#8f8f8f"/> + android:background="#8f8f8f" /> </RelativeLayout> diff --git a/libs/emojicon/src/main/res/values/attrs.xml b/libs/emojicon/src/main/res/values/attrs.xml index 9810158dc..f4f21f903 100644 --- a/libs/emojicon/src/main/res/values/attrs.xml +++ b/libs/emojicon/src/main/res/values/attrs.xml @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- +<?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright 2014 Ankush Sachdeva ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); |