Search in sources :

Example 6 with Activity

use of android.app.Activity in project persistence by casidiablo.

the class RawQueryTest method findAllByClassTest.

@Test
public void findAllByClassTest() {
    List<ExampleAutoincrement> collection = new ArrayList<ExampleAutoincrement>();
    Random random = new Random();
    for (int i = 0; i < 100; i++) {
        ExampleAutoincrement foo = new ExampleAutoincrement();
        foo.name = "Foo Bar " + random.nextInt();
        foo.number = random.nextInt();
        foo.decimal = random.nextFloat();
        foo.bool = random.nextBoolean();
        foo.blob = foo.name.getBytes();
        collection.add(foo);
    }
    getAdapter().storeCollection(collection, null);
    RawQuery rawQuery = Persistence.getRawQuery(new Activity());
    Cursor cursor = rawQuery.findAll("automatic", null, null, null, null, null, "number ASC", null);
    assertNotNull(cursor);
    assertEquals(100, cursor.getCount());
    assertTrue(cursor.moveToFirst());
    Collections.sort(collection, new Comparator<ExampleAutoincrement>() {

        @Override
        public int compare(ExampleAutoincrement foo, ExampleAutoincrement bar) {
            if (foo.number < 0 && bar.number >= 0) {
                return -1;
            }
            if (foo.number >= 0 && bar.number < 0) {
                return 1;
            }
            return foo.number - bar.number;
        }
    });
    int i = 0;
    do {
        ExampleAutoincrement item = collection.get(i);
        assertEquals(item.name, cursor.getString(cursor.getColumnIndex("name")));
        assertEquals(item.number, cursor.getInt(cursor.getColumnIndex("number")));
        assertEquals(item.decimal, cursor.getFloat(cursor.getColumnIndex("decimal")), 0.0f);
        assertEquals(item.bool, cursor.getInt(cursor.getColumnIndex("bool")) == 1);
        assertEquals(new String(item.blob), new String(cursor.getBlob(cursor.getColumnIndex("blob"))));
        i++;
    } while (cursor.moveToNext());
}
Also used : RawQuery(com.codeslap.persistence.RawQuery) Activity(android.app.Activity) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 7 with Activity

use of android.app.Activity in project persistence by casidiablo.

the class RawQueryTest method findAllBySample.

@Test
public void findAllBySample() {
    ExampleAutoincrement foo = new ExampleAutoincrement();
    foo.name = "Foo Bar";
    foo.number = 111;
    foo.decimal = 222f;
    foo.bool = false;
    foo.blob = foo.name.getBytes();
    getAdapter().store(foo);
    foo = new ExampleAutoincrement();
    foo.name = "Bar Foo";
    foo.number = 333;
    foo.decimal = 444f;
    foo.bool = true;
    foo.blob = foo.name.getBytes();
    getAdapter().store(foo);
    RawQuery rawQuery = Persistence.getRawQuery(new Activity());
    ExampleAutoincrement sample = new ExampleAutoincrement();
    sample.bool = true;
    Cursor cursor = rawQuery.findAll(sample);
    assertNotNull(cursor);
    assertTrue(cursor.moveToFirst());
    assertEquals(2, cursor.getLong(cursor.getColumnIndex("_id")));
    assertEquals(foo.name, cursor.getString(cursor.getColumnIndex("name")));
    assertEquals(foo.number, cursor.getInt(cursor.getColumnIndex("number")));
    assertEquals(foo.decimal, cursor.getFloat(cursor.getColumnIndex("decimal")), 0.0f);
    assertEquals(foo.bool, cursor.getInt(cursor.getColumnIndex("bool")) == 1);
}
Also used : RawQuery(com.codeslap.persistence.RawQuery) Activity(android.app.Activity) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 8 with Activity

use of android.app.Activity in project persistence by casidiablo.

the class PrefHelperTest method prefHelperTest.

@Test
public void prefHelperTest() {
    PreferencesAdapter adapter = Persistence.getPreferenceAdapter(new Activity());
    assertNotNull(adapter);
    adapter = Persistence.getPreferenceAdapter(new Activity(), "test.pref");
    assertNotNull(adapter);
}
Also used : Activity(android.app.Activity) PreferencesAdapter(com.codeslap.persistence.PreferencesAdapter) Test(org.junit.Test)

Example 9 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 10 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)

Aggregations

Activity (android.app.Activity)1138 View (android.view.View)200 Test (org.junit.Test)166 Intent (android.content.Intent)162 TextView (android.widget.TextView)83 ArrayList (java.util.ArrayList)62 Bundle (android.os.Bundle)53 Context (android.content.Context)51 ViewGroup (android.view.ViewGroup)48 DialogInterface (android.content.DialogInterface)44 AlertDialog (android.app.AlertDialog)41 Robolectric.buildActivity (org.robolectric.Robolectric.buildActivity)40 ImageView (android.widget.ImageView)36 Twitter (twitter4j.Twitter)35 LayoutInflater (android.view.LayoutInflater)34 AppCompatActivity (android.support.v7.app.AppCompatActivity)32 DisplayMetrics (android.util.DisplayMetrics)32 FrameLayout (android.widget.FrameLayout)28 Robolectric.setupActivity (org.robolectric.Robolectric.setupActivity)28 FragmentActivity (android.support.v4.app.FragmentActivity)27