use of android.app.Activity in project UltimateAndroid by cymcsg.
the class ViewPagerTabListViewFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.observable_scroll_view_fragment_listview, container, false);
Activity parentActivity = getActivity();
final ObservableListView listView = (ObservableListView) view.findViewById(R.id.list);
listView.addHeaderView(inflater.inflate(R.layout.observable_scroll_view_padding, null));
List<String> items = new ArrayList<String>();
for (int i = 1; i <= 100; i++) {
items.add("Item " + i);
}
listView.setAdapter(new ArrayAdapter<String>(parentActivity, android.R.layout.simple_list_item_1, items));
if (parentActivity instanceof ObservableScrollViewCallbacks) {
// Scroll to the specified position after layout
Bundle args = getArguments();
if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
ViewTreeObserver vto = listView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
// scrollTo() doesn't work, should use setSelection()
listView.setSelection(initialPosition);
}
});
}
listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
}
return view;
}
use of android.app.Activity in project UltimateAndroid by cymcsg.
the class ViewPagerTabScrollViewFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.observable_scroll_view_fragment_scrollview, container, false);
final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
Activity parentActivity = getActivity();
if (parentActivity instanceof ObservableScrollViewCallbacks) {
// Scroll to the specified offset after layout
Bundle args = getArguments();
if (args != null && args.containsKey(ARG_SCROLL_Y)) {
final int scrollY = args.getInt(ARG_SCROLL_Y, 0);
ViewTreeObserver vto = scrollView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
scrollView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
scrollView.scrollTo(0, scrollY);
}
});
}
scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
}
return view;
}
use of android.app.Activity in project android-betterpickers by code-troopers.
the class TimePickerDialogFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.time_picker_dialog, container, false);
Button doneButton = (Button) view.findViewById(R.id.done_button);
Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
cancelButton.setTextColor(mTextColor);
doneButton.setTextColor(mTextColor);
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (TimePickerDialogHandler handler : mTimePickerDialogHandlers) {
handler.onDialogTimeSet(mReference, mPicker.getHours(), mPicker.getMinutes());
}
final Activity activity = getActivity();
final Fragment fragment = getTargetFragment();
if (activity instanceof TimePickerDialogHandler) {
final TimePickerDialogHandler act = (TimePickerDialogHandler) activity;
act.onDialogTimeSet(mReference, mPicker.getHours(), mPicker.getMinutes());
} else if (fragment instanceof TimePickerDialogHandler) {
final TimePickerDialogHandler frag = (TimePickerDialogHandler) fragment;
frag.onDialogTimeSet(mReference, mPicker.getHours(), mPicker.getMinutes());
}
dismiss();
}
});
mPicker = (TimePicker) view.findViewById(R.id.time_picker);
mPicker.setSetButton(doneButton);
mPicker.setTheme(mTheme);
getDialog().getWindow().setBackgroundDrawableResource(mDialogBackgroundResId);
return view;
}
use of android.app.Activity in project materialistic by hidroh.
the class FavoriteActivityTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
TestApplication.applicationGraph.inject(this);
reset(favoriteManager);
reset(userServices);
reset(keyDelegate);
reset(actionViewResolver.getActionView(mock(MenuItem.class)));
controller = Robolectric.buildActivity(TestFavoriteActivity.class);
when(favoriteManager.getSize()).thenReturn(2);
when(favoriteManager.getItem(eq(0))).thenReturn(new TestFavorite("1", "http://example.com", "title", System.currentTimeMillis()));
when(favoriteManager.getItem(eq(1))).thenReturn(new TestFavorite("2", "http://example.com", "ask HN", System.currentTimeMillis()));
// skip menu due to search view
activity = controller.create().postCreate(null).start().resume().visible().get();
recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
adapter = recyclerView.getAdapter();
shadowAdapter = customShadowOf(adapter);
fragment = activity.getSupportFragmentManager().findFragmentById(android.R.id.list);
verify(keyDelegate).attach(any(Activity.class));
verify(favoriteManager).attach(any(Context.class), any(LoaderManager.class), observerCaptor.capture(), any());
}
use of android.app.Activity in project AndroidTraining by mixi-inc.
the class SampleRobotiumTestCase method testCallSubActivityAndReturn.
public void testCallSubActivityAndReturn() throws Exception {
Activity activity = getActivity();
Solo solo = new Solo(getInstrumentation(), activity);
// MainActivity が立ち上がってフォアグラウンドにいる
solo.assertCurrentActivity("MainActivity now.", MainActivity.class);
// カウンタの数字が 0 であることを確認する
// 0 と書かれた TextView を画面上から探し出し、あればその TextView オブジェクトを返すメソッド
assertTrue(solo.searchText("0"));
// Count up と書かれたボタンをクリックする (View の id を知る必要はない)
solo.clickOnButton("Count up");
// 0 と書かれた TextView はなくなり、1 と書かれたTextView になるはず
assertFalse(solo.searchText("0"));
assertTrue(solo.searchText("1"));
// Launch SubActivity ボタンを押す
solo.clickOnButton("Launch SubActivity");
// SubActivity が起動し、フォアグラウンドに居るはず
solo.assertCurrentActivity("SubActivity now.", SubActivity.class);
// メニューキーを押した
solo.sendKey(KeyEvent.KEYCODE_MENU);
// ActionBarを使っているなら、以下でも良い
// solo.clickOnActionBarItem(0);
// 戻る
solo.getCurrentActivity().finish();
// 状態復帰できているはず
assertTrue(solo.searchText("1"));
}
Aggregations