Skip to content

Instantly share code, notes, and snippets.

View izmajlowiczl's full-sized avatar

Łukasz Izmajłowicz izmajlowiczl

View GitHub Profile
@izmajlowiczl
izmajlowiczl / LegalFragment.java
Last active September 5, 2018 16:12
[Android] WebView back button
// Handles back button inside WebView.
// When user clicks back button and web history is not empty shows previous page from history.
mWebView.setOnKeyListener( new View.OnKeyListener() {
@Override
public boolean onKey( View v, int keyCode, KeyEvent event ) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
@izmajlowiczl
izmajlowiczl / MainActivity.java
Created May 29, 2013 09:47
Android Show Notification with NotificationCompat
createNotification(Calendar.getInstance().getTimeInMillis(), "hey!");
public static final String NOTIFICATION_DATA = "NOTIFICATION_DATA";
private void createNotification(long when, String data){
String notificationContent ="Notification Content Click Here to go more details";
String notificationTitle ="This is Notification";
//large icon for notification,normally use App icon
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
int smalIcon =R.drawable.ic_launcher;
String notificationData="This is data : "+data;
@izmajlowiczl
izmajlowiczl / EmailValidator
Created April 24, 2013 06:36
[Android] Simple Email Validation
public boolean isValid(final CharSequence email) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
@izmajlowiczl
izmajlowiczl / Test_UserScore_GetValue.java
Created March 10, 2013 20:13
TestingExceptionsWithMessage
@Test
public void GetScore_GetForNotExistingUser_ThrowException() {
final UserScoreRepository userScoreRepositoryStub = Make_FakeUserScoreRepository();
final UserScoreService userScore = new UserScoreService(userScoreRepositoryStub);
final User fakeUser = null;
try {
final int userPoints = userScore.get(fakeUser);
} catch (IllegalArgumentException e) {
final String errorMessage = "User Is null";
@TestWith({
"0",
"1",
"2"
})
public void AddScore_AddPositiveScore_IncreaseExistingScore(int value) throws Exception {
final UserScoreRepository userScoreRepositoryStub = Make_FakeUserScoreRepository();
final User fakeUser = Make_User();
final UserScoreService userScore = new UserScoreService(userScoreRepositoryStub);