This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_fullscreen); | |
| inputEditText = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1); | |
| inputEditText.setTokenizer(new UsernameTokenizer()); | |
| inputEditText.addTextChangedListener( this ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UsernameTokenizer implements Tokenizer { | |
| @Override public CharSequence terminateToken(CharSequence text) { | |
| int i = text.length(); | |
| while (i > 0 && text.charAt(i - 1) == ' ') { i--; } | |
| if (text instanceof Spanned) { | |
| SpannableString sp = new SpannableString(text + " "); | |
| TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0); | |
| return sp; | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override public void afterTextChanged(Editable editable) {} | |
| @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} | |
| @Override public void onTextChanged(CharSequence s, int start, int before, int count) { | |
| int cursor = start; | |
| if (cursor >= s.length()) cursor = s.length()-1; | |
| if (isValidToken(s, cursor)){ | |
| String token = getToken(s, start); | |
| new LinkedinSkillAsyncTask( this ).execute( token ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Checks if the current word being edited is a valid token (e.g. starts with @ and has no spaces) | |
| * @param text - all text being edited in input | |
| * @param cursor - current position of text change | |
| * @return is valid | |
| */ | |
| private boolean isValidToken(CharSequence text, int cursor){ | |
| for (int i=cursor; i>=0; i--){ | |
| if (text.charAt(i) == '@') return true; | |
| if (text.charAt(i) == ' ') return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LinkedinSkillAsyncTask extends AsyncTask<String, String, String>{ | |
| private Activity context; | |
| public String data; | |
| public List<String> suggest; | |
| public ArrayAdapter<String> aAdapter; | |
| public LinkedinSkillAsyncTask(Activity cntxt) { | |
| context = cntxt; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Merge two already sorted lists | |
| */ | |
| def mergeSortedLists( List leftList, List rightList ){ | |
| def result = [] | |
| def n = (leftList.size() + rightList.size())-1 | |
| def leftHead=0, rightHead=0 | |
| (0..n).each { | |
| if ( rightHead!=rightList.size() && (leftHead==leftList.size() || rightList[rightHead] <= leftList[leftHead]) ) { result << rightList.get(rightHead); rightHead++ } else | |
| if ( leftHead!=leftList.size() && (rightHead==rightList.size() || leftList[leftHead] < rightList[rightHead]) ) { result << leftList.get(leftHead); leftHead++ } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Sort a list - recursively divide and conquer | |
| */ | |
| def mergeSort( List input ){ | |
| if ( input.isEmpty() || input.size() == 1 ){ | |
| input | |
| } else { | |
| int pivot = Math.floor( input.size()/2 ) | |
| List left = input.subList(0, pivot) | |
| List right = input.subList(pivot, input.size()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Grandparent { | |
| public Grandparent doStuff( String s ){ | |
| println "GP $s" | |
| this | |
| } | |
| } | |
| class Parent extends Grandparent{ | |
| public Parent doStuff( String s ){ | |
| println "P $s " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Merge sort implementation. Runs in O(nlogn) time | |
| */ | |
| public List<Integer> mergeSort( List<Integer> input ){ | |
| //Base case - if 1 element in the list, return as already sorted | |
| if ( input.size() == 1){ | |
| return input; | |
| } | |
| // Divide & recurse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Quick sort implementation. Runs in O(nlogn) time, but also in O(1) memory/space | |
| */ | |
| public List<Integer> quickSort( List<Integer> input, int startIndex, int endIndex ){ | |
| //base case - one element then return, but we need to consider pointers | |
| if (startIndex == endIndex){ | |
| return input; | |
| } | |
| //Sort current section of the list around pivot |