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());
}
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);
}
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);
}
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 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;
}
Aggregations