diff --git a/remixer_example/src/main/AndroidManifest.xml b/remixer_example/src/main/AndroidManifest.xml index a11d785..a4d2548 100644 --- a/remixer_example/src/main/AndroidManifest.xml +++ b/remixer_example/src/main/AndroidManifest.xml @@ -13,26 +13,44 @@ ~ 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. - --> +--> + - + + + + - - - - - - - - - + + + + + + + + + + diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/BoxActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/BoxActivity.java new file mode 100644 index 0000000..52e2bb5 --- /dev/null +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/BoxActivity.java @@ -0,0 +1,73 @@ +package com.google.android.apps.remixer; + +import android.graphics.Color; +import android.media.Image; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.TypedValue; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; +import com.google.android.libraries.remixer.BooleanVariableBuilder; +import com.google.android.libraries.remixer.Callback; +import com.google.android.libraries.remixer.ItemListVariable; +import com.google.android.libraries.remixer.RangeVariable; +import com.google.android.libraries.remixer.Variable; +import com.google.android.libraries.remixer.Remixer; +import com.google.android.libraries.remixer.StringVariableBuilder; +import com.google.android.libraries.remixer.Trigger; +import com.google.android.libraries.remixer.annotation.BooleanVariableMethod; +import com.google.android.libraries.remixer.annotation.IntegerListVariableMethod; +import com.google.android.libraries.remixer.annotation.RangeVariableMethod; +import com.google.android.libraries.remixer.annotation.RemixerBinder; +import com.google.android.libraries.remixer.ui.gesture.Direction; +import com.google.android.libraries.remixer.ui.view.RemixerFragment; + +/** + * This activity reuses one of the values from variables in MainActivity. + */ +public class BoxActivity extends AppCompatActivity { + + // A title text whose text size is set by a variable. + private TextView titleText; + // An ImageView that does nothing but draw a box with its background color. + private ImageView box; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_box); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + // Find all UI widgets + titleText = (TextView) findViewById(R.id.titleText); + box = (ImageView) findViewById(R.id.box); + // Initialize the remixer instance + RemixerBinder.bind(this); + RemixerFragment remixerFragment = RemixerFragment.newInstance(); + remixerFragment.attachToGesture(this, Direction.UP, 3); + } + + @RangeVariableMethod( + key = "titleTextSize", title = "(Shared) title text size", + minValue = 16, maxValue = 72, increment = 4 + ) + public void setTitleTextSize(Integer size) { + titleText.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); + } + + @BooleanVariableMethod(key = "showBox", title = "Show box") + void showBox(Boolean show) { + box.setVisibility(show ? View.VISIBLE : View.GONE); + } + + @IntegerListVariableMethod( + key = "boxColor", title = "Box color", + possibleValues = {Color.DKGRAY, Color.LTGRAY, Color.MAGENTA, Color.CYAN} + ) + void setBoxColor(Integer color) { + box.setBackgroundColor(color); + } +} + diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java index 6bb6f63..765ea1c 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java @@ -1,129 +1,79 @@ +/* + * Copyright 2016 Google Inc. + * + * 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.google.android.apps.remixer; -import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.TypedValue; -import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; -import com.google.android.libraries.remixer.BooleanVariableBuilder; -import com.google.android.libraries.remixer.Callback; -import com.google.android.libraries.remixer.ItemListVariable; -import com.google.android.libraries.remixer.RangeVariable; -import com.google.android.libraries.remixer.Variable; -import com.google.android.libraries.remixer.Remixer; -import com.google.android.libraries.remixer.StringVariableBuilder; -import com.google.android.libraries.remixer.Trigger; +import com.google.android.libraries.remixer.annotation.RangeVariableMethod; +import com.google.android.libraries.remixer.annotation.RemixerBinder; +import com.google.android.libraries.remixer.annotation.StringListVariableMethod; +import com.google.android.libraries.remixer.annotation.StringVariableMethod; +import com.google.android.libraries.remixer.annotation.TriggerMethod; import com.google.android.libraries.remixer.ui.gesture.Direction; import com.google.android.libraries.remixer.ui.view.RemixerFragment; /** - * Main activity with explicit instantiation of Remixer Objects. + * Example activity where remixer is used to control text size and text values. */ public class MainActivity extends AppCompatActivity { - // A text view whose text is updated by an ItemListVariable and font size by a - // RangeVariable - private TextView boundedText; - // A text view whose text is updated by a StringVariable and is visible depending on a - // BooleanVariable + private TextView titleText; private TextView freeformText; - // The remixer instance - private Remixer remixer; + private Button remixerButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - // Find all UI widgets - Button remixerButton = (Button) findViewById(R.id.button); - boundedText = (TextView) findViewById(R.id.boundedText); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + titleText = (TextView) findViewById(R.id.titleText); freeformText = (TextView) findViewById(R.id.freeformText); - // Initialize the remixer instance - remixer = Remixer.getInstance(); - - ItemListVariable.Builder colorVariable = new ItemListVariable.Builder() - .setKey("color") - .setParentObject(this) - .setPossibleValues(new Integer[] {Color.DKGRAY, Color.LTGRAY, Color.MAGENTA, Color.CYAN} ) - .setCallback(new Callback() { - @Override - public void onValueSet(Variable variable) { - boundedText.setTextColor(variable.getSelectedValue()); - freeformText.setTextColor(variable.getSelectedValue()); - } - }) - .setLayoutId(R.layout.color_list_variable_widget); - remixer.addItem(colorVariable.buildAndInit()); + remixerButton = (Button) findViewById(R.id.button); + RemixerBinder.bind(this); - // Create a RangeVariable that updates boundedText's size between 10 and 48 sp. - RangeVariable.Builder fontSizeRangeVariable = new RangeVariable.Builder() - .setKey("font_size") - .setParentObject(this) - .setMinValue(16) - .setMaxValue(72) - .setIncrement(4) - .setCallback(new Callback() { - @Override - public void onValueSet(Variable variable) { - boundedText.setTextSize(TypedValue.COMPLEX_UNIT_SP, variable.getSelectedValue()); - } - }); - remixer.addItem(fontSizeRangeVariable.buildAndInit()); - - // Create an ItemListVariable that updates boundedText's contents from a list of options - ItemListVariable.Builder itemListVariable = new ItemListVariable.Builder() - .setKey("boundedText") - .setParentObject(this) - .setPossibleValues(new String[] {"Hello world", "Foo", "Bar", "May the force be with you"}) - .setCallback( - new Callback() { - @Override - public void onValueSet(Variable variable) { - boundedText.setText(variable.getSelectedValue()); - } - }); - remixer.addItem(itemListVariable.buildAndInit()); + RemixerFragment remixerFragment = RemixerFragment.newInstance(); + remixerFragment.attachToGesture(this, Direction.UP, 3); + remixerFragment.attachToButton(this, remixerButton); + } - // Create a BooleanVariable that controls whether freeformText is visible or not. - Variable.Builder booleanVariable = new BooleanVariableBuilder() - .setKey("freeformTextDisplay") - .setParentObject(this) - .setCallback(new Callback() { - @Override - public void onValueSet(Variable variable) { - freeformText.setVisibility(variable.getSelectedValue() ? View.VISIBLE : View.GONE); - } - }); - remixer.addItem(booleanVariable.buildAndInit()); + @RangeVariableMethod( + key = "titleTextSize", + minValue = 16, maxValue = 72, increment = 4, title = "(Shared) Title font size") + void setTitleTextSize(Integer size) { + titleText.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); + } - // Create a StringVariable that lets you set freeformText's content freely. - Variable.Builder freeformStringVariable = new StringVariableBuilder() - .setKey("freeformText") - .setParentObject(this) - .setDefaultValue("Change me!") - .setCallback(new Callback() { - @Override - public void onValueSet(Variable variable) { - freeformText.setText(variable.getSelectedValue()); - } - }); - remixer.addItem(freeformStringVariable.buildAndInit()); + @StringListVariableMethod( + title = "Title text", + possibleValues = {"Hello World", "Alohomora", "Foo", "Bar", "May the force be with you"}) + void setTitleText(String text) { + titleText.setText(text); + } - Trigger trigger = new Trigger("Toast", "toast", this, new Runnable() { - @Override - public void run() { - String value = freeformText.getText().toString(); - Toast.makeText(MainActivity.this, value, Toast.LENGTH_SHORT).show(); - } - }); - remixer.addItem(trigger); + @StringVariableMethod(defaultValue = "Change me!") + void setFreeformText(String text) { + freeformText.setText(text); + } - RemixerFragment remixerFragment = RemixerFragment.newInstance(); - remixerFragment.attachToButton(this, remixerButton); - remixerFragment.attachToGesture(this, Direction.UP, 3); + @TriggerMethod + void toast() { + Toast.makeText(this, freeformText.getText(), Toast.LENGTH_SHORT).show(); } } - diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivityAnnotated.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivityAnnotated.java deleted file mode 100644 index 96393c8..0000000 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivityAnnotated.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * 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.google.android.apps.remixer; - -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.ColorInt; -import android.support.v7.app.AppCompatActivity; -import android.util.TypedValue; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; -import android.widget.Toast; -import com.google.android.libraries.remixer.annotation.BooleanVariableMethod; -import com.google.android.libraries.remixer.annotation.IntegerListVariableMethod; -import com.google.android.libraries.remixer.annotation.RangeVariableMethod; -import com.google.android.libraries.remixer.annotation.RemixerBinder; -import com.google.android.libraries.remixer.annotation.StringListVariableMethod; -import com.google.android.libraries.remixer.annotation.StringVariableMethod; -import com.google.android.libraries.remixer.annotation.TriggerMethod; -import com.google.android.libraries.remixer.ui.gesture.Direction; -import com.google.android.libraries.remixer.ui.view.RemixerFragment; - -/** - * Annotated version of the MainActivity. - */ -public class MainActivityAnnotated extends AppCompatActivity { - - TextView boundedText; - TextView freeformText; - Button remixerButton; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - boundedText = (TextView) findViewById(R.id.boundedText); - freeformText = (TextView) findViewById(R.id.freeformText); - remixerButton = (Button) findViewById(R.id.button); - RemixerBinder.bind(this); - - RemixerFragment remixerFragment = RemixerFragment.newInstance(); - remixerFragment.attachToGesture(this, Direction.UP, 3); - remixerFragment.attachToButton(this, remixerButton); - } - - @IntegerListVariableMethod( - possibleValues = {Color.DKGRAY, Color.LTGRAY, Color.MAGENTA, Color.CYAN}, - layoutId = R.layout.color_list_variable_widget - ) - void setTextColor(@ColorInt Integer color) { - boundedText.setTextColor(color); - freeformText.setTextColor(color); - } - - @RangeVariableMethod(minValue = 16, maxValue = 72, increment = 4) - void setTextSize(Integer size) { - boundedText.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); - } - - @StringListVariableMethod( - possibleValues = {"Hello World", "Alohomora", "Foo", "Bar", "May the force be with you"}) - void setBoundedText(String text) { - boundedText.setText(text); - } - - @BooleanVariableMethod - void setFreeformVisible(Boolean visibility) { - freeformText.setVisibility(visibility ? View.VISIBLE : View.GONE); - } - - @StringVariableMethod(defaultValue = "Change me!") - void setFreeformText(String text) { - freeformText.setText(text); - } - - @TriggerMethod - void toast() { - Toast.makeText(this, freeformText.getText(), Toast.LENGTH_SHORT).show(); - } -} diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MenuActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MenuActivity.java new file mode 100644 index 0000000..9af2f09 --- /dev/null +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/MenuActivity.java @@ -0,0 +1,81 @@ +/* + * Copyright 2016 Google Inc. + * + * 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.google.android.apps.remixer; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.StringRes; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +public class MenuActivity extends AppCompatActivity { + + private RecyclerView list; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_menu); + list = (RecyclerView) findViewById(R.id.exampleList); + list.setAdapter(new RecyclerView.Adapter() { + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ViewHolder( + LayoutInflater.from(MenuActivity.this).inflate(R.layout.list_text, null)); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + int textId = position == 0 ? R.string.mainDemoName : R.string.boxDemoName; + Class activityClass = position == 0 ? MainActivity.class : BoxActivity.class; + holder.setContent(textId, activityClass); + } + + @Override + public int getItemCount() { + return 2; + } + }); + } + + class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + + Class activityClass; + + ViewHolder(View itemView) { + super(itemView); + itemView.setOnClickListener(this); + } + + void setContent(@StringRes int string, Class activityClass) { + ((TextView) itemView).setText(string); + this.activityClass = activityClass; + } + + @Override + public void onClick(View view) { + Intent intent = new Intent(); + intent.setClass(MenuActivity.this, activityClass); + startActivity(intent); + } + } +} diff --git a/remixer_example/src/main/res/layout/activity_box.xml b/remixer_example/src/main/res/layout/activity_box.xml new file mode 100644 index 0000000..0bc41ee --- /dev/null +++ b/remixer_example/src/main/res/layout/activity_box.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + diff --git a/remixer_example/src/main/res/layout/activity_main.xml b/remixer_example/src/main/res/layout/activity_main.xml index 8543601..7514b83 100644 --- a/remixer_example/src/main/res/layout/activity_main.xml +++ b/remixer_example/src/main/res/layout/activity_main.xml @@ -15,32 +15,30 @@ ~ limitations under the License. --> - + - + - + -