am 80116aac: Polished Wizard example for Showcase app
* commit '80116aacde385b9ff63b5aaccb5ef653b870fff3': Polished Wizard example for Showcase app
This commit is contained in:
@@ -24,7 +24,8 @@ import android.support.v17.leanback.widget.GuidedAction;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: JavaDoc
|
* The first screen of the rental wizard. Gives the user the choice between renting the movie in SD
|
||||||
|
* or HD quality.
|
||||||
*/
|
*/
|
||||||
public class WizardExample1stStepFragment extends WizardExampleBaseStepFragment {
|
public class WizardExample1stStepFragment extends WizardExampleBaseStepFragment {
|
||||||
|
|
||||||
@@ -66,10 +67,8 @@ public class WizardExample1stStepFragment extends WizardExampleBaseStepFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuidedActionClicked(GuidedAction action) {
|
public void onGuidedActionClicked(GuidedAction action) {
|
||||||
GuidedStepFragment fragment = new WizardExample2ndStepFragment();
|
boolean rentHd = ACTION_ID_BUY_HD == action.getId();
|
||||||
Bundle args = getArguments(); // Reuse the same arguments this fragment was given.
|
GuidedStepFragment fragment = WizardExample2ndStepFragment.build(rentHd, this);
|
||||||
args.putBoolean("hd", ACTION_ID_BUY_HD == action.getId());
|
|
||||||
fragment.setArguments(args);
|
|
||||||
add(getFragmentManager(), fragment);
|
add(getFragmentManager(), fragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,13 +28,23 @@ import android.widget.Toast;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: JavaDoc
|
* Displays the second screen of the rental wizard which requires the user to confirm his purchase.
|
||||||
*/
|
*/
|
||||||
public class WizardExample2ndStepFragment extends WizardExampleBaseStepFragment {
|
public class WizardExample2ndStepFragment extends WizardExampleBaseStepFragment {
|
||||||
|
|
||||||
|
private static final String ARG_HD = "hd";
|
||||||
private static final int ACTION_ID_CONFIRM = 1;
|
private static final int ACTION_ID_CONFIRM = 1;
|
||||||
private static final int ACTION_ID_PAYMENT_METHOD = ACTION_ID_CONFIRM + 1;
|
private static final int ACTION_ID_PAYMENT_METHOD = ACTION_ID_CONFIRM + 1;
|
||||||
|
|
||||||
|
public static GuidedStepFragment build(boolean hd, WizardExampleBaseStepFragment previousFragment) {
|
||||||
|
GuidedStepFragment fragment = new WizardExample2ndStepFragment();
|
||||||
|
// Reuse the same arguments this fragment was given.
|
||||||
|
Bundle args = previousFragment.getArguments();
|
||||||
|
args.putBoolean(ARG_HD, hd);
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -50,35 +60,9 @@ public class WizardExample2ndStepFragment extends WizardExampleBaseStepFragment
|
|||||||
return guidance;
|
return guidance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public GuidedActionsStylist onCreateActionsStylist() {
|
|
||||||
GuidedActionsStylist stylist = new GuidedActionsStylist() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(ViewHolder vh, GuidedAction action) {
|
|
||||||
super.onBindViewHolder(vh, action);
|
|
||||||
|
|
||||||
if (ACTION_ID_CONFIRM == action.getId()) {
|
|
||||||
Drawable background = getResources().getDrawable(
|
|
||||||
R.drawable.wizard_important_action_item_background, null);
|
|
||||||
vh.view.setBackground(background);
|
|
||||||
vh.getTitleView().setTextColor(Color.parseColor("#666666"));
|
|
||||||
vh.getDescriptionView().setTextColor(Color.parseColor("#666666"));
|
|
||||||
} else {
|
|
||||||
vh.view.setBackground(null);
|
|
||||||
vh.getTitleView().setTextColor(getResources().getColor(android.support.v17.leanback.R.color.lb_guidedactions_item_unselected_text_color,
|
|
||||||
getActivity().getTheme()));
|
|
||||||
vh.getDescriptionView().setTextColor(getResources().getColor(android.support.v17.leanback.R.color.lb_guidedactions_item_unselected_text_color,
|
|
||||||
getActivity().getTheme()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return stylist;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
|
public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
|
||||||
boolean rentHighDefinition = getArguments().getBoolean("hd");
|
boolean rentHighDefinition = getArguments().getBoolean(ARG_HD);
|
||||||
|
|
||||||
GuidedAction action = new GuidedAction.Builder()
|
GuidedAction action = new GuidedAction.Builder()
|
||||||
.id(ACTION_ID_CONFIRM)
|
.id(ACTION_ID_CONFIRM)
|
||||||
@@ -89,7 +73,7 @@ public class WizardExample2ndStepFragment extends WizardExampleBaseStepFragment
|
|||||||
action = new GuidedAction.Builder()
|
action = new GuidedAction.Builder()
|
||||||
.id(ACTION_ID_PAYMENT_METHOD)
|
.id(ACTION_ID_PAYMENT_METHOD)
|
||||||
.title(getString(R.string.wizard_example_payment_method))
|
.title(getString(R.string.wizard_example_payment_method))
|
||||||
.description("Visa - 1234 Balance $60.00")
|
.description(getString(R.string.wizard_example_visa_balance))
|
||||||
.build();
|
.build();
|
||||||
actions.add(action);
|
actions.add(action);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import android.support.v17.leanback.widget.GuidedActionsStylist;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: JavaDoc
|
* This is the third screen of the rental wizard which will display a progressbar while waiting for
|
||||||
|
* the server to process the rental. The server communication is faked for the sake of this example
|
||||||
|
* by waiting four seconds until continuing.
|
||||||
*/
|
*/
|
||||||
public class WizardExample3rdStepFragment extends WizardExampleBaseStepFragment {
|
public class WizardExample3rdStepFragment extends WizardExampleBaseStepFragment {
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ public class WizardExample3rdStepFragment extends WizardExampleBaseStepFragment
|
|||||||
@Override
|
@Override
|
||||||
public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
|
public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
|
||||||
GuidanceStylist.Guidance guidance = new GuidanceStylist.Guidance(mMovie.getTitle(),
|
GuidanceStylist.Guidance guidance = new GuidanceStylist.Guidance(mMovie.getTitle(),
|
||||||
"Just a second...",
|
getString(R.string.wizard_example_just_a_second),
|
||||||
mMovie.getBreadcrump(), null);
|
mMovie.getBreadcrump(), null);
|
||||||
return guidance;
|
return guidance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ import android.widget.Toast;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: JavaDoc
|
* The last screen of the Wizard gives to options to either watch the rented movie now or later. Due
|
||||||
|
* to keep this example simple and focused on the usage of the GuidedStepFragment, clicking on
|
||||||
|
* either action will end the wizard. You might however start a new Activity playing the movie.
|
||||||
*/
|
*/
|
||||||
public class WizardExample4thStepFragment extends WizardExampleBaseStepFragment {
|
public class WizardExample4thStepFragment extends WizardExampleBaseStepFragment {
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import android.support.v17.leanback.app.GuidedStepFragment;
|
|||||||
import android.support.v17.leanback.supportleanbackshowcase.R;
|
import android.support.v17.leanback.supportleanbackshowcase.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Javadoc
|
* An Activity displaying a wizard for renting a movie.
|
||||||
*/
|
*/
|
||||||
public class WizardExampleActivity extends Activity {
|
public class WizardExampleActivity extends Activity {
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ import android.support.v17.leanback.supportleanbackshowcase.models.Movie;
|
|||||||
import android.support.v17.leanback.supportleanbackshowcase.R;
|
import android.support.v17.leanback.supportleanbackshowcase.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: JavaDoc
|
* A base class which provides all it's implementations with a method #getWizardActivity(). It also
|
||||||
|
* makes sure that the wizard is using the correct theme.
|
||||||
*/
|
*/
|
||||||
public class WizardExampleBaseStepFragment extends GuidedStepFragment {
|
public abstract class WizardExampleBaseStepFragment extends GuidedStepFragment {
|
||||||
|
|
||||||
protected Movie mMovie;
|
protected Movie mMovie;
|
||||||
|
|
||||||
@@ -35,12 +36,12 @@ public class WizardExampleBaseStepFragment extends GuidedStepFragment {
|
|||||||
if (!(getActivity() instanceof WizardExampleActivity)) {
|
if (!(getActivity() instanceof WizardExampleActivity)) {
|
||||||
throw new IllegalStateException(WizardExampleActivity.class.getName() + " expected.");
|
throw new IllegalStateException(WizardExampleActivity.class.getName() + " expected.");
|
||||||
}
|
}
|
||||||
return (WizardExampleActivity)getActivity();
|
return (WizardExampleActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
mMovie = (Movie)getArguments().getSerializable("movie");
|
mMovie = (Movie) getArguments().getSerializable("movie");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,4 +85,6 @@
|
|||||||
<string name="wizard_example_watch_now">Watch now</string>
|
<string name="wizard_example_watch_now">Watch now</string>
|
||||||
<string name="wizard_example_later">Later</string>
|
<string name="wizard_example_later">Later</string>
|
||||||
<string name="wizard_example_watch_now_clicked">\'Watch now\' clicked.</string>
|
<string name="wizard_example_watch_now_clicked">\'Watch now\' clicked.</string>
|
||||||
|
<string name="wizard_example_visa_balance">Visa - 1234 Balance $60.00</string>
|
||||||
|
<string name="wizard_example_just_a_second">Just a second...</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user