From 9dc90d28efac6852721bf1b08a73020dd7f95ee2 Mon Sep 17 00:00:00 2001 From: Pedro Diaz Date: Thu, 29 Sep 2016 11:53:53 -0400 Subject: [PATCH] Testing with a library --- app/build.gradle | 2 + .../snorlax/app/rename/RenameActivity.java | 13 ++++ .../app/rename/RenameCompletionView.java | 61 +++++++++++++++++++ .../snorlax/app/rename/RenameOptions.java | 32 ++++++++++ 4 files changed, 108 insertions(+) create mode 100644 app/src/main/java/com/icecream/snorlax/app/rename/RenameCompletionView.java create mode 100644 app/src/main/java/com/icecream/snorlax/app/rename/RenameOptions.java diff --git a/app/build.gradle b/app/build.gradle index 2045e0c..471aa25 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -132,4 +132,6 @@ dependencies { provided libraries.autoValueAnnotations provided libraries.xposed + + compile 'com.splitwise:tokenautocomplete:2.0.8@aar' } diff --git a/app/src/main/java/com/icecream/snorlax/app/rename/RenameActivity.java b/app/src/main/java/com/icecream/snorlax/app/rename/RenameActivity.java index 92325c0..6c06ebf 100644 --- a/app/src/main/java/com/icecream/snorlax/app/rename/RenameActivity.java +++ b/app/src/main/java/com/icecream/snorlax/app/rename/RenameActivity.java @@ -20,6 +20,7 @@ import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.widget.ArrayAdapter; import com.icecream.snorlax.R; @@ -42,6 +43,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { mUnbinder = ButterKnife.bind(this); setupToolbar(); + setupOptions(); } private void setupToolbar() { @@ -51,4 +53,15 @@ private void setupToolbar() { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } + + private void setupOptions() { + RenameOptions[] options = new RenameOptions[]{ + RenameOptions.create("IV"), + RenameOptions.create("ATT"), + RenameOptions.create("DEF"), + RenameOptions.create("STA") + }; + + ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, options); + } } diff --git a/app/src/main/java/com/icecream/snorlax/app/rename/RenameCompletionView.java b/app/src/main/java/com/icecream/snorlax/app/rename/RenameCompletionView.java new file mode 100644 index 0000000..19680ab --- /dev/null +++ b/app/src/main/java/com/icecream/snorlax/app/rename/RenameCompletionView.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016. Pedro Diaz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.icecream.snorlax.app.rename; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; + +import com.tokenautocomplete.TokenCompleteTextView; + +@SuppressWarnings({"unused", "WeakerAccess", "FieldCanBeLocal"}) +public class RenameCompletionView extends TokenCompleteTextView { + + private final LayoutInflater mLayoutInflater; + + public RenameCompletionView(Context context, AttributeSet attrs) { + super(context, attrs); + mLayoutInflater = LayoutInflater.from(context); + } + + @Override + protected View getViewForObject(RenameOptions person) { + /* + TextView view = (TextView) mLayoutInflater.inflate(R.layout.contact_token, (ViewGroup) getParent(), false); + view.setText(person.getOption()); + return view; + */ + return null; + } + + @Override + protected RenameOptions defaultObject(String completionText) { + //Stupid simple example of guessing if we have an email or not + /* + int index = completionText.indexOf('@'); + + if (index == -1) { + return new Person(completionText, completionText.replace(" ", "") + "@example.com"); + } + else { + return new Person(completionText.substring(0, index), completionText); + } + */ + return RenameOptions.create("Dummy"); + } +} diff --git a/app/src/main/java/com/icecream/snorlax/app/rename/RenameOptions.java b/app/src/main/java/com/icecream/snorlax/app/rename/RenameOptions.java new file mode 100644 index 0000000..a03ffc7 --- /dev/null +++ b/app/src/main/java/com/icecream/snorlax/app/rename/RenameOptions.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016. Pedro Diaz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.icecream.snorlax.app.rename; + +import java.io.Serializable; + +import com.google.auto.value.AutoValue; + +@AutoValue +@SuppressWarnings({"unused", "WeakerAccess", "FieldCanBeLocal"}) +abstract class RenameOptions implements Serializable { + + static RenameOptions create(String option) { + return new AutoValue_RenameOptions(option); + } + + abstract String getOption(); +}