15d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin/*
25d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Copyright (C) 2013 Square, Inc.
35d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin *
45d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Licensed under the Apache License, Version 2.0 (the "License");
55d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * you may not use this file except in compliance with the License.
65d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * You may obtain a copy of the License at
75d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin *
85d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * http://www.apache.org/licenses/LICENSE-2.0
95d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin *
105d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Unless required by applicable law or agreed to in writing, software
115d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * distributed under the License is distributed on an "AS IS" BASIS,
125d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * See the License for the specific language governing permissions and
145d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * limitations under the License.
155d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin */
165d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinpackage com.example.dagger.activitygraphs.ui;
175d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
185d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport android.app.Activity;
195d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport com.example.dagger.activitygraphs.PerActivity;
205d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport javax.inject.Inject;
215d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
225d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin/**
235d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * A simple abstraction which provides the ability to set the title on an activity.
245d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * <p>
255d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Fragments should not directly modify any part of an activity outside of the view or dialog that
265d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * it creates. This class provides a way for fragments to inject a controller that will allow for
275d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * control of the activity title. While not exceedingly useful in practice, this concept could be
285d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * expanded to things like facilitating control over the action bar, dialogs, notifications, etc.
295d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin */
305d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin@PerActivity
315d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinpublic class ActivityTitleController {
325d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  private final Activity activity;
335d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
345d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  @Inject public ActivityTitleController(Activity activity) {
355d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    this.activity = activity;
365d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  }
375d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
385d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  public void setTitle(CharSequence title) {
395d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    activity.setTitle(title);
405d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  }
415d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin}
42