use of android.os.Build in project Awful.apk by Awful.
the class ThreadDisplayFragment method ignoreUser.
/**
* Add a user to the ignore list.
*
* @param userId The awful ID of the user
*/
public void ignoreUser(int userId) {
final Activity activity = getActivity();
if (getPrefs().ignoreFormkey == null) {
queueRequest(new ProfileRequest(activity, null).build());
}
if (getPrefs().showIgnoreWarning) {
DialogInterface.OnClickListener onClickListener = (dialog, which) -> {
if (which == AlertDialog.BUTTON_NEUTRAL) {
// cancel future alerts if the user clicks the "don't warn" option
getPrefs().setPreference(Keys.SHOW_IGNORE_WARNING, false);
}
doIgnoreUser(activity, userId);
};
new AlertDialog.Builder(activity).setPositiveButton(R.string.confirm, onClickListener).setNeutralButton(R.string.dont_show_again, onClickListener).setNegativeButton(R.string.cancel, null).setTitle(R.string.ignore_title).setMessage(R.string.ignore_message).show();
} else {
doIgnoreUser(activity, userId);
}
}
use of android.os.Build in project Awful.apk by Awful.
the class ThreadDisplayFragment method rateThread.
/**
* Display a thread-rating dialog.
*
* This handles the network request to submit the vote, and user feedback.
*/
private void rateThread() {
final CharSequence[] items = { "1", "2", "3", "4", "5" };
final Activity activity = this.getActivity();
new AlertDialog.Builder(activity).setTitle("Rate this thread").setItems(items, (dialog, item) -> queueRequest(new VoteRequest(activity, getThreadId(), item).build(ThreadDisplayFragment.this, new AwfulRequest.AwfulResultCallback<Void>() {
@Override
public void success(Void result) {
getAlertView().setTitle(R.string.vote_succeeded).setSubtitle(R.string.vote_succeeded_sub).setIcon(R.drawable.ic_mood).show();
}
@Override
public void failure(VolleyError error) {
}
}))).show();
}
use of android.os.Build in project realm-java by realm.
the class RealmTests method numberOfVersionsDecreasedOnClose.
// Test for https://github.com/realm/realm-java/issues/6977
@Test
public void numberOfVersionsDecreasedOnClose() {
realm.close();
looperThread.runBlocking(() -> {
int count = 50;
final CountDownLatch bgThreadDoneLatch = new CountDownLatch(count);
RealmConfiguration config = configFactory.createConfigurationBuilder().directory(context.getFilesDir()).name("versions-test.realm").maxNumberOfActiveVersions(5).build();
Realm.deleteRealm(config);
// Synchronizes between change listener and Background writes so they operate in lockstep.
AtomicReference<CountDownLatch> guard = new AtomicReference<>(new CountDownLatch(1));
Realm realm = Realm.getInstance(config);
looperThread.closeAfterTest(realm);
realm.addChangeListener(callbackRealm -> {
// This test catches a bug that caused ObjectStore to pin Realm versions
// if a TableView was created inside a change notification and no elements
// in the TableView was accessed.
RealmResults<AllJavaTypes> query = realm.where(AllJavaTypes.class).findAll();
guard.get().countDown();
bgThreadDoneLatch.countDown();
if (bgThreadDoneLatch.getCount() == 0) {
looperThread.testComplete();
}
});
// Write a number of transactions in the background in a serial manner
// in order to create a number of different versions. Done in serial
// to allow the LooperThread to catch up.
new Thread(() -> {
for (int i = 0; i < count; i++) {
Thread t = new Thread() {
@Override
public void run() {
Realm realm = Realm.getInstance(config);
realm.executeTransaction(bgRealm -> {
});
realm.close();
}
};
t.start();
try {
t.join();
TestHelper.awaitOrFail(guard.get());
guard.set(new CountDownLatch(1));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}).start();
});
}
use of android.os.Build in project realm-java by realm.
the class RealmTests method encryption_stressTest.
// Test for https://github.com/realm/realm-java/issues/6152
@Test
// See https://github.com/realm/realm-java/issues/7628
@Ignore
public void encryption_stressTest() {
realm.close();
looperThread.runBlocking(() -> {
final int WRITER_TRANSACTIONS = 50;
final int TEST_OBJECTS = 100_000;
final int MAX_STRING_LENGTH = 1000;
final AtomicInteger id = new AtomicInteger(0);
long seed = System.nanoTime();
Random random = new Random(seed);
RealmConfiguration config = configFactory.createConfigurationBuilder().name("encryption-stress-test.realm").encryptionKey(TestHelper.getRandomKey(seed)).build();
Realm.deleteRealm(config);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Realm realm = Realm.getInstance(config);
for (int i = 0; i < WRITER_TRANSACTIONS; i++) {
realm.executeTransaction(r -> {
for (int j = 0; j < (TEST_OBJECTS / WRITER_TRANSACTIONS); j++) {
AllJavaTypes obj = new AllJavaTypes(id.incrementAndGet());
obj.setFieldString(TestHelper.getRandomString(random.nextInt(MAX_STRING_LENGTH)));
r.insert(obj);
}
});
}
realm.close();
}
});
t.start();
Realm realm = Realm.getInstance(config);
looperThread.closeAfterTest(realm);
RealmResults<AllJavaTypes> results = realm.where(AllJavaTypes.class).findAllAsync();
looperThread.keepStrongReference(results);
results.addChangeListener(new OrderedRealmCollectionChangeListener<RealmResults<AllJavaTypes>>() {
@Override
public void onChange(RealmResults<AllJavaTypes> results, OrderedCollectionChangeSet changeSet) {
for (AllJavaTypes obj : results) {
String s = obj.getFieldString();
}
if (results.size() == TEST_OBJECTS) {
try {
t.join(5000);
} catch (InterruptedException e) {
fail("workerthread failed to finish in time.");
}
looperThread.testComplete();
}
}
});
});
}
use of android.os.Build in project Signal-Android by signalapp.
the class Megaphones method buildNotificationsMegaphone.
@NonNull
private static Megaphone buildNotificationsMegaphone(@NonNull Context context) {
return new Megaphone.Builder(Event.NOTIFICATIONS, Megaphone.Style.BASIC).setTitle(R.string.NotificationsMegaphone_turn_on_notifications).setBody(R.string.NotificationsMegaphone_never_miss_a_message).setImage(R.drawable.megaphone_notifications_64).setActionButton(R.string.NotificationsMegaphone_turn_on, (megaphone, controller) -> {
if (Build.VERSION.SDK_INT >= 26 && !NotificationChannels.isMessageChannelEnabled(context)) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, NotificationChannels.getMessagesChannel(context));
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
controller.onMegaphoneNavigationRequested(intent);
} else if (Build.VERSION.SDK_INT >= 26 && (!NotificationChannels.areNotificationsEnabled(context) || !NotificationChannels.isMessagesChannelGroupEnabled(context))) {
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
controller.onMegaphoneNavigationRequested(intent);
} else {
controller.onMegaphoneNavigationRequested(AppSettingsActivity.notifications(context));
}
}).setSecondaryButton(R.string.NotificationsMegaphone_not_now, (megaphone, controller) -> controller.onMegaphoneSnooze(Event.NOTIFICATIONS)).build();
}
Aggregations