提交 3edd8038 编写于 作者: E Eric Frohnhoefer

Replace anonymous inner class with lambda

Change-Id: I9b4b81c778cf025e9d10e4c364373c6e983c76c5
上级 6fa3b709
......@@ -28,23 +28,20 @@ import android.support.test.runner.AndroidJUnitRunner;
public class SpoonInstrumentationTestRunner extends AndroidJUnitRunner {
@Override
public void onStart() {
runOnMainSync(new Runnable() {
@Override
public void run() {
final Application app = (Application) getTargetContext().getApplicationContext();
final String simpleName = SpoonInstrumentationTestRunner.class.getSimpleName();
runOnMainSync(() -> {
final Application app = (Application) getTargetContext().getApplicationContext();
final String simpleName = SpoonInstrumentationTestRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
((KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE))
.newKeyguardLock(simpleName)
.disableKeyguard();
// Unlock the device so that the tests can input keystrokes.
((KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE))
.newKeyguardLock(simpleName)
.disableKeyguard();
// Wake up the screen.
((PowerManager) app.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager
.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, simpleName)
.acquire();
}
// Wake up the screen.
((PowerManager) app.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager
.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, simpleName)
.acquire();
});
super.onStart();
......
......@@ -51,28 +51,20 @@ public class TweetComposerMainActivity extends BaseActivity {
}
final Button tweetComposer = findViewById(R.id.tweet_composer);
tweetComposer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
new TweetComposer.Builder(TweetComposerMainActivity.this)
.text("Tweet from TwitterKit!")
.url(new URL("http://www.twitter.com"))
.show();
tweetComposer.setOnClickListener(view -> {
try {
new TweetComposer.Builder(TweetComposerMainActivity.this)
.text("Tweet from TwitterKit!")
.url(new URL("http://www.twitter.com"))
.show();
} catch (MalformedURLException e) {
Log.e(TAG, "error creating tweet intent", e);
}
} catch (MalformedURLException e) {
Log.e(TAG, "error creating tweet intent", e);
}
});
final Button organicComposer = findViewById(R.id.organic_composer);
organicComposer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
launchPicker();
}
});
organicComposer.setOnClickListener(view -> launchPicker());
}
void launchPicker() {
......
......@@ -105,27 +105,24 @@ public class TimelineActivity extends BaseActivity {
});
// specify action to take on swipe refresh
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeLayout.setRefreshing(true);
adapter.refresh(new Callback<TimelineResult<Tweet>>() {
@Override
public void success(Result<TimelineResult<Tweet>> result) {
swipeLayout.setRefreshing(false);
}
swipeLayout.setOnRefreshListener(() -> {
swipeLayout.setRefreshing(true);
adapter.refresh(new Callback<TimelineResult<Tweet>>() {
@Override
public void success(Result<TimelineResult<Tweet>> result) {
swipeLayout.setRefreshing(false);
}
@Override
public void failure(TwitterException exception) {
swipeLayout.setRefreshing(false);
final Activity activity = activityRef.get();
if (activity != null && !activity.isFinishing()) {
Toast.makeText(activity, exception.getMessage(),
Toast.LENGTH_SHORT).show();
}
@Override
public void failure(TwitterException exception) {
swipeLayout.setRefreshing(false);
final Activity activity = activityRef.get();
if (activity != null && !activity.isFinishing()) {
Toast.makeText(activity, exception.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
}
}
});
});
}
}
......@@ -84,22 +84,16 @@ public class TweetPreviewActivity extends TweetUiActivity {
final Button lightButton = v.findViewById(R.id.button_show_light);
final Button darkButton = v.findViewById(R.id.button_show_dark);
lightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final long tweetId = Long.parseLong(selectorInput.getText().toString());
tweetRegion.removeAllViews();
loadTweet(tweetId, tweetRegion, R.style.tw__TweetLightStyle);
}
lightButton.setOnClickListener(v12 -> {
final long tweetId = Long.parseLong(selectorInput.getText().toString());
tweetRegion.removeAllViews();
loadTweet(tweetId, tweetRegion, R.style.tw__TweetLightStyle);
});
darkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final long tweetId = Long.parseLong(selectorInput.getText().toString());
tweetRegion.removeAllViews();
loadTweet(tweetId, tweetRegion, R.style.tw__TweetDarkStyle);
}
darkButton.setOnClickListener(v1 -> {
final long tweetId = Long.parseLong(selectorInput.getText().toString());
tweetRegion.removeAllViews();
loadTweet(tweetId, tweetRegion, R.style.tw__TweetDarkStyle);
});
return v;
......
......@@ -38,77 +38,32 @@ public class TweetUiMainActivity extends BaseActivity {
}
final Button xmlTweetButton = findViewById(R.id.button_xml_tweet_activity);
xmlTweetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, XmlTweetActivity.class));
}
});
xmlTweetButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, XmlTweetActivity.class)));
final Button tweetActivityButton = findViewById(R.id.button_tweet_activity);
tweetActivityButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, TweetActivity.class));
}
});
tweetActivityButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, TweetActivity.class)));
final Button unqiueTweetButton = findViewById(R.id.button_unique_tweet_activity);
unqiueTweetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, UniqueTweetActivity.class));
}
});
unqiueTweetButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, UniqueTweetActivity.class)));
final Button tweetListButton = findViewById(R.id.button_fixed_timeline_activity);
tweetListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, FixedTimelineActivity.class));
}
});
tweetListButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, FixedTimelineActivity.class)));
final Button timelineButton = findViewById(R.id.button_refresh_timeline_activity);
timelineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, TimelineActivity.class));
}
});
timelineButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, TimelineActivity.class)));
final Button timelinesButton = findViewById(R.id.button_timelines_activity);
timelinesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(TweetUiMainActivity.this, TimelinesActivity.class));
}
});
timelinesButton.setOnClickListener(view -> startActivity(new Intent(TweetUiMainActivity.this, TimelinesActivity.class)));
final Button tweetSelectorButton = findViewById(
R.id.button_tweet_preview_activity);
tweetSelectorButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, TweetPreviewActivity.class));
}
});
tweetSelectorButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, TweetPreviewActivity.class)));
final Button tweetPojoButton = findViewById(
R.id.button_tweet_pojo_activity);
tweetPojoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, TweetPojoActivity.class));
}
});
tweetPojoButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, TweetPojoActivity.class)));
final Button rtlTimelineButton = findViewById(R.id.button_rtl_timeline_activity);
rtlTimelineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TweetUiMainActivity.this, RtlTimelineActivity.class));
}
});
rtlTimelineButton.setOnClickListener(v -> startActivity(new Intent(TweetUiMainActivity.this, RtlTimelineActivity.class)));
}
}
......@@ -23,7 +23,6 @@ import android.net.Uri;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
......@@ -81,26 +80,13 @@ public class ComposerView extends LinearLayout {
super.onFinishInflate();
findSubviews();
closeView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
callbacks.onCloseClick();
}
});
closeView.setOnClickListener(view -> callbacks.onCloseClick());
tweetButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
callbacks.onTweetPost(getTweetText());
}
});
tweetButton.setOnClickListener(view -> callbacks.onTweetPost(getTweetText()));
tweetEditView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
callbacks.onTweetPost(getTweetText());
return true;
}
tweetEditView.setOnEditorActionListener((textView, i, keyEvent) -> {
callbacks.onTweetPost(getTweetText());
return true;
});
tweetEditView.addTextChangedListener(new TextWatcher() {
......@@ -118,14 +104,11 @@ public class ComposerView extends LinearLayout {
}
});
scrollView.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
@Override
public void onScrollChanged(int scrollY) {
if (scrollY > 0) {
divider.setVisibility(View.VISIBLE);
} else {
divider.setVisibility(View.INVISIBLE);
}
scrollView.setScrollViewListener(scrollY -> {
if (scrollY > 0) {
divider.setVisibility(View.VISIBLE);
} else {
divider.setVisibility(View.INVISIBLE);
}
});
}
......
......@@ -161,11 +161,8 @@ public abstract class AbstractTweetViewTest extends TweetUiTestCase {
public void testSetTweetMediaClickListener() {
final AbstractTweetView view = createView(context, TestFixtures.TEST_TWEET_LINK);
view.setTweetMediaClickListener(new TweetMediaClickListener() {
@Override
public void onMediaEntityClick(Tweet tweet, MediaEntity entity) {
view.setTweetMediaClickListener((tweet, entity) -> {
}
});
assertNotNull(view.tweetMediaClickListener);
......
......@@ -193,11 +193,8 @@ public abstract class BaseTweetViewTest extends TweetUiTestCase {
public void testSetTweetMediaClickListener() {
final BaseTweetView view = createView(context, TestFixtures.TEST_TWEET_LINK);
view.setTweetMediaClickListener(new TweetMediaClickListener() {
@Override
public void onMediaEntityClick(Tweet tweet, MediaEntity entity) {
view.setTweetMediaClickListener((tweet, entity) -> {
}
});
assertNotNull(view.tweetMediaClickListener);
......
......@@ -429,19 +429,16 @@ abstract class AbstractTweetView extends RelativeLayout{
protected LinkClickListener getLinkClickListener() {
if (linkClickListener == null) {
linkClickListener = new LinkClickListener() {
@Override
public void onUrlClicked(String url) {
if (TextUtils.isEmpty(url)) return;
if (tweetLinkClickListener != null) {
tweetLinkClickListener.onLinkClick(tweet, url);
} else {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (!IntentUtils.safeStartActivity(getContext(), intent)) {
Twitter.getLogger().e(TweetUi.LOGTAG,
"Activity cannot be found to open URL");
}
linkClickListener = url -> {
if (TextUtils.isEmpty(url)) return;
if (tweetLinkClickListener != null) {
tweetLinkClickListener.onLinkClick(tweet, url);
} else {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (!IntentUtils.safeStartActivity(getContext(), intent)) {
Twitter.getLogger().e(TweetUi.LOGTAG,
"Activity cannot be found to open URL");
}
}
};
......
......@@ -415,44 +415,38 @@ public abstract class BaseTweetView extends AbstractTweetView {
*/
void linkifyProfilePhotoView(final Tweet displayTweet) {
if (displayTweet != null && displayTweet.user != null) {
avatarView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (tweetLinkClickListener != null) {
tweetLinkClickListener.onLinkClick(displayTweet,
TweetUtils.getProfilePermalink(displayTweet.user.screenName));
} else {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
TweetUtils.getProfilePermalink(displayTweet.user.screenName)));
if (!IntentUtils.safeStartActivity(getContext(), intent)) {
Twitter.getLogger().e(TweetUi.LOGTAG,
"Activity cannot be found to open URL");
}
avatarView.setOnClickListener(v -> {
if (tweetLinkClickListener != null) {
tweetLinkClickListener.onLinkClick(displayTweet,
TweetUtils.getProfilePermalink(displayTweet.user.screenName));
} else {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
TweetUtils.getProfilePermalink(displayTweet.user.screenName)));
if (!IntentUtils.safeStartActivity(getContext(), intent)) {
Twitter.getLogger().e(TweetUi.LOGTAG,
"Activity cannot be found to open URL");
}
}
});
avatarView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final ImageView imageView = (ImageView) v;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
imageView.getDrawable().setColorFilter(getResources().getColor(
R.color.tw__black_opacity_10), PorterDuff.Mode.SRC_ATOP);
imageView.invalidate();
break;
case MotionEvent.ACTION_UP:
v.performClick();
case MotionEvent.ACTION_CANCEL: {
imageView.getDrawable().clearColorFilter();
imageView.invalidate();
break;
}
default: break;
avatarView.setOnTouchListener((v, event) -> {
final ImageView imageView = (ImageView) v;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
imageView.getDrawable().setColorFilter(getResources().getColor(
R.color.tw__black_opacity_10), PorterDuff.Mode.SRC_ATOP);
imageView.invalidate();
break;
case MotionEvent.ACTION_UP:
v.performClick();
case MotionEvent.ACTION_CANCEL: {
imageView.getDrawable().clearColorFilter();
imageView.invalidate();
break;
}
return false;
default: break;
}
return false;
});
}
}
......
......@@ -100,22 +100,14 @@ class FilterTimelineDelegate extends TimelineDelegate<Tweet> {
@Override
public void success(final Result<TimelineResult<Tweet>> result) {
final Runnable timelineFilterRunnable = new Runnable() {
@Override
public void run() {
final List<Tweet> filteredTweets = timelineFilter.filter(result.data.items);
final TimelineResult<Tweet> filteredTimelineResult =
buildTimelineResult(result.data.timelineCursor, filteredTweets);
handler.post(new Runnable() {
@Override
public void run() {
callback.success(new Result<>(filteredTimelineResult, result.response));
}
});
scribeFilteredTimeline(result.data.items, filteredTweets);
}
final Runnable timelineFilterRunnable = () -> {
final List<Tweet> filteredTweets = timelineFilter.filter(result.data.items);
final TimelineResult<Tweet> filteredTimelineResult =
buildTimelineResult(result.data.timelineCursor, filteredTweets);
handler.post(() -> callback.success(new Result<>(filteredTimelineResult, result.response)));
scribeFilteredTimeline(result.data.items, filteredTweets);
};
executorService.execute(timelineFilterRunnable);
......
......@@ -69,24 +69,16 @@ class PlayerController {
final View.OnTouchListener listener = SwipeToDismissTouchListener
.createFromView(videoView, callback);
videoView.setOnTouchListener(listener);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
videoView.setOnPreparedListener(mediaPlayer -> videoProgressView.setVisibility(View.GONE));
videoView.setOnInfoListener((mediaPlayer, what, extra) -> {
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
videoProgressView.setVisibility(View.GONE);
return true;
} else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
videoProgressView.setVisibility(View.VISIBLE);
return true;
}
});
videoView.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
videoProgressView.setVisibility(View.GONE);
return true;
} else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
videoProgressView.setVisibility(View.VISIBLE);
return true;
}
return false;
}
return false;
});
final Uri uri = Uri.parse(item.url);
videoView.setVideoURI(uri, item.looping);
......@@ -126,14 +118,11 @@ class PlayerController {
void setUpLoopControl() {
videoControlView.setVisibility(View.INVISIBLE);
videoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (videoView.isPlaying()) {
videoView.pause();
} else {
videoView.start();
}
videoView.setOnClickListener(view -> {
if (videoView.isPlaying()) {
videoView.pause();
} else {
videoView.start();
}
});
}
......@@ -152,25 +141,19 @@ class PlayerController {
}
void setUpCallToActionListener(final String callToActionUrl) {
callToActionView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Uri uri = Uri.parse(callToActionUrl);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
IntentUtils.safeStartActivity(callToActionView.getContext(), intent);
}
callToActionView.setOnClickListener(v -> {
final Uri uri = Uri.parse(callToActionUrl);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
IntentUtils.safeStartActivity(callToActionView.getContext(), intent);
});
}
void setUpRootViewOnClickListener() {
rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (callToActionView.getVisibility() == View.VISIBLE) {
callToActionView.setVisibility(View.GONE);
} else {
callToActionView.setVisibility(View.VISIBLE);
}
rootView.setOnClickListener(v -> {
if (callToActionView.getVisibility() == View.VISIBLE) {
callToActionView.setVisibility(View.GONE);
} else {
callToActionView.setVisibility(View.VISIBLE);
}
});
}
......
......@@ -95,12 +95,7 @@ class TweetRepository {
*/
private void deliverTweet(final Tweet tweet, final Callback<Tweet> cb) {
if (cb == null) return;
mainHandler.post(new Runnable() {
@Override
public void run() {
cb.success(new Result<>(tweet, null));
}
});
mainHandler.post(() -> cb.success(new Result<>(tweet, null)));
}
void favorite(final long tweetId, final Callback<Tweet> cb) {
......
......@@ -29,7 +29,6 @@ import com.twitter.sdk.android.tweetui.internal.TweetMediaUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;