Search in sources :

Example 1 with Activity

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;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Activity(android.app.Activity) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) View(android.view.View) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ViewTreeObserver(android.view.ViewTreeObserver)

Example 2 with Activity

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;
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) Bundle(android.os.Bundle) Activity(android.app.Activity) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) ViewTreeObserver(android.view.ViewTreeObserver)

Example 3 with Activity

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;
}
Also used : Button(android.widget.Button) Activity(android.app.Activity) View(android.view.View) Fragment(android.support.v4.app.Fragment) DialogFragment(android.support.v4.app.DialogFragment)

Example 4 with Activity

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());
}
Also used : Context(android.content.Context) LoaderManager(android.support.v4.app.LoaderManager) TestFavoriteActivity(io.github.hidroh.materialistic.test.TestFavoriteActivity) TestFavoriteActivity(io.github.hidroh.materialistic.test.TestFavoriteActivity) Activity(android.app.Activity) TestFavorite(io.github.hidroh.materialistic.data.TestFavorite) Before(org.junit.Before)

Example 5 with Activity

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"));
}
Also used : Solo(com.jayway.android.robotium.solo.Solo) SubActivity(jp.mixi.sample.test.SubActivity) MainActivity(jp.mixi.sample.test.MainActivity) Activity(android.app.Activity)

Aggregations

Activity (android.app.Activity)3221 Intent (android.content.Intent)612 View (android.view.View)536 Test (org.junit.Test)456 TextView (android.widget.TextView)263 Context (android.content.Context)220 ArrayList (java.util.ArrayList)201 Bundle (android.os.Bundle)197 DialogInterface (android.content.DialogInterface)167 SettingsActivity (com.android.settings.SettingsActivity)167 ViewGroup (android.view.ViewGroup)133 ImageView (android.widget.ImageView)116 AlertDialog (android.app.AlertDialog)109 LayoutInflater (android.view.LayoutInflater)109 Preference (android.support.v7.preference.Preference)83 PackageManager (android.content.pm.PackageManager)76 Uri (android.net.Uri)76 EditText (android.widget.EditText)72 ComponentName (android.content.ComponentName)71 Handler (android.os.Handler)71