Skip to content

Commit

Permalink
Merge pull request #9 from ama-csail/hover
Browse files Browse the repository at this point in the history
Hover
  • Loading branch information
williamcaruso committed Apr 9, 2017
2 parents b10c2c0 + a9f9c79 commit b49a0e5
Show file tree
Hide file tree
Showing 35 changed files with 1,153 additions and 159 deletions.
3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ama/build.gradle
Expand Up @@ -19,6 +19,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
Expand All @@ -31,4 +34,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
compile 'com.github.ama-csail:hover:0e7cab23d6'
}
16 changes: 14 additions & 2 deletions ama/src/main/AndroidManifest.xml
@@ -1,11 +1,23 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.mit.dig.ama">
package="edu.mit.dig.ama">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<application
android:allowBackup="true"
android:label="@string/app_name"
android:allowBackup="true"
android:supportsRtl="true">

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="edu.mit.dig.ama.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>

</application>

</manifest>
103 changes: 89 additions & 14 deletions ama/src/main/java/edu/mit/dig/ama/core/AMA.java
Expand Up @@ -10,16 +10,20 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.SystemClock;
import android.provider.Settings;
import android.support.annotation.ColorRes;
import android.support.annotation.IntegerRes;
import android.support.annotation.LayoutRes;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -359,13 +363,55 @@ public static void checkNavigationOnlySpeech(View view) {
}

/**
* Get the current available input methods from the input field
* @param view the view to check upon
* Get the current available input methods
* @param activity the Activity for specific input field
* @return list of string representing different types of input methods
*/
public static void getInputMethodsInInputFields(View view, Activity activity) {
//TODO
throw new RuntimeException("Method not implemented");
public static String[] getAvailableInputMethods(Activity activity) {
String enabledMethods = Settings.Secure.getString(activity.getContentResolver(),Settings.Secure.ENABLED_INPUT_METHODS);
return enabledMethods.split(":");
}

/**
* Check if the voice typing is enabled for the phone
* @param enabledMethods list of string representing enabled methods
* @return boolean representing whether voice typing is enabled or not
*/
public static boolean isVoiceTypingEnabled(String[] enabledMethods) {
for (String method: enabledMethods) {
if (method.contains("VoiceInputMethod")) {
return true;
}
}
return false;
}

/**
* Get all the text input fields from the view.
* @param activity the Activity for specific input field
* @return list of text input fields existing on all views
*/
public static List<View> getAllTextInputFields(Activity activity) {
List<View> views = getAllViews(activity);
List<View> inputFields = new ArrayList<>();
for (View view: views) {
if (view instanceof EditText) {
inputFields.add(view);
}
}
return inputFields;
}

/**
* Get the default input method for the activity
* @param activity current activity
* @return String representing the default input method
*/
public static String getDefaultInputMethod(Activity activity) {
//activity.getApplicationContext()
String id;
id = Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
return id;
}

/**
Expand Down Expand Up @@ -480,6 +526,34 @@ public static void setSingleHandGestures(Activity activity) {
throw new RuntimeException("Method not implemented");
}


/**
* Simulates a touch gesture at a specific location on a view
* @param view The view to touch
* @param x The x-coordinate of the touch
* @param y The y-coordinate of the touch
*/
public static void simulateTouchGesture(View view, float x, float y) {
// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
// List of meta states found here:
// developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_UP,
x,
y,
metaState
);

// Dispatch touch event to view
view.dispatchTouchEvent(motionEvent);
}


/**
* Sets the input time for a View
* @param view The View to set
Expand Down Expand Up @@ -557,23 +631,24 @@ public static void checkFeedbackOnlySpeech(View view) {
//----------------------------------------------------------------------------------------------

/**
* Sets the HelpMessage of a View
* Sets the HelpMessage of a View (essentially a piece of information
* which can be used in other operations)
* @param view The view to set the helpMessage on
* @param helpMessage The string to set
*/
public static void setHelpMessage(View view, String helpMessage) {
//TODO
throw new RuntimeException("Method not implemented");
view.setTag(Util.HELP_MESSAGE_KEY, helpMessage);
}

/**
* Gets the HelpMessage of a View
* Gets the HelpMessage of a View (the piece of information set by
* <code>setHelpMessage()</code>)
* @param view The view to get the HelpMessage on
* @return The String HelpMessage of the view
* @return The String HelpMessage of the view, or null if it does not exist
*/
public static String getHelpMessage(View view) {
//TODO
throw new RuntimeException("Method not implemented");
Object help = view.getTag(Util.HELP_MESSAGE_KEY);
return (help == null ? null : (String) help);
}

/**
Expand Down Expand Up @@ -807,7 +882,7 @@ public static void setFeedbackMessage(View view, String feedbackMessage) {
* Gets action feedback for a View
* @param view The view to get the feedbackMessage from
*/
public static void getFeedbackMessage(View view){
public static void getFeedbackMessage(View view) {
//TODO
throw new RuntimeException("Method not implemented");
}
Expand All @@ -817,7 +892,7 @@ public static void getFeedbackMessage(View view){
* @param paragraph The String to break down
* @return bulleted version of paragraph
*/
public static String getBullettedString(String paragraph){
public static String getBullettedString(String paragraph) {
//TODO
throw new RuntimeException("Method not implemented");
}
Expand Down
@@ -1,7 +1,17 @@
package edu.mit.dig.ama.core;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;

import edu.mit.dig.ama.core.menu.MenuView;
import edu.mit.dig.ama.core.menu.MenuViewParser;
import edu.mit.dig.ama.core.menu.services.navigation.IntentEntry;
import edu.mit.dig.ama.core.util.exceptions.MenuNotCreatedException;

/**
* An accessible library which provides accessible features which a developer can
Expand All @@ -14,6 +24,35 @@
public class AccessibleAppCompatActivity extends Activity {

private boolean orientationChangedListenerEnabled;
private MenuView accessibleMenu;

/**
* Enable the accessibility menu for this activity (note that this enables
* any settings configured by the user within the activity)
*/
public void enableMenu() {
if(accessibleMenu == null) {
Log.d("MENU", "Getting menu");
accessibleMenu = MenuView.getMenu(this.getApplicationContext());
}
accessibleMenu.setEnabled(true);
}

/**
* Disable the accessibility menu for this activity (note that this disables
* any settings configured by the user within the activity)
*/
public void disableMenu() {
if(accessibleMenu == null) {
accessibleMenu = MenuView.getMenu(this.getApplicationContext());
}
accessibleMenu.setEnabled(false);
}

public void showMenu() {
MenuViewParser viewParser = new MenuViewParser(this, accessibleMenu.getConfiguration());
viewParser.prepareMenu();
}

/**
* Enables the orientation changed listener for this activity
Expand Down Expand Up @@ -51,4 +90,54 @@ public void onConfigurationChanged(Configuration newConfig) {

}

/** code to post/handler request for permission */
public final static int REQUEST_CODE = -1010101;

public void checkDrawOverlayPermission() {
/** check if we already have permission to draw over other apps */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
/** if not construct intent to request permission */
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
/** request permission via start activity for result */
startActivityForResult(intent, REQUEST_CODE);
}
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
/** check if received result code
is equal our requested code for draw permission */
if (requestCode == REQUEST_CODE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.canDrawOverlays(this)) {
// continue here - permission was granted
MenuViewParser viewParser = new MenuViewParser(this, null);
viewParser.prepareMenu();
}
}
}
}

// MODULE - SPECIFIC BINDINGS FOR THE MENU CONFIGURATION -------------------

/**
* Provides a sitemap to the navigation module of the accessibility menu
* @param title The title to display
* @param intentEntries
*/
public void giveSitemap(String title, IntentEntry... intentEntries) {

if(accessibleMenu != null) {
accessibleMenu.getConfiguration()
.getNavigationMenuModule()
.setSitemap(title, intentEntries);
} else {
throw new MenuNotCreatedException();
}

}

}

0 comments on commit b49a0e5

Please sign in to comment.