[关闭]
@iar 2016-09-24T09:49:46.000000Z 字数 13036 阅读 131

Work Sample

BurningFire


The code break down

  1. C:\Users\Administrator\StudioProjects\BF-Android-App\app\src\main\java\com\burningfire\BFandroidapp>tree /F
  2. Folder PATH listing
  3. Volume serial number is C038-3181
  4. C:.
  5. ├───api
  6. AuthorizationInterceptor.java
  7. DiscoverResponse.java
  8. CitieReviewsResponse.java
  9. CitieVideosResponse.java
  10. TheCitieDbClient.java
  11. TheCitieDbService.java
  12. ├───data
  13. FavoritesService.java
  14. Citie.java
  15. CitieReview.java
  16. CitiesContract.java
  17. CitiesDbHelper.java
  18. CitiesProvider.java
  19. CitiesService.java
  20. CitieVideo.java
  21. Sort.java
  22. SortHelper.java
  23. ├───ui
  24. EndlessRecyclerViewOnScrollListener.java
  25. ItemOffsetDecoration.java
  26. MainActivity.java
  27. ProportionalImageView.java
  28. SortingDialogFragment.java
  29. SplashActivity.java
  30. ├───detail
  31. CitieDetailActivity.java
  32. CitieDetailFragment.java
  33. CitieReviewsAdapter.java
  34. CitieReviewViewHolder.java
  35. CitieVideosAdapter.java
  36. CitieVideoViewHolder.java
  37. └───grid
  38. AbstractCitiesGridFragment.java
  39. FavoritesGridFragment.java
  40. CitieGridItemViewHolder.java
  41. CitiesAdapter.java
  42. CitiesGridFragment.java
  43. └───util
  44. CursorRecyclerViewAdapter.java
  45. OnItemClickListener.java
  46. OnItemSelectedListener.java

Frontend

  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. AhoyOnboarderCard ahoyOnboarderCard1 = new AhoyOnboarderCard("旅行安排", "旅行是给自己一个重新认识自己,认识世界的机会.", R.drawable.backpack);
  5. AhoyOnboarderCard ahoyOnboarderCard2 = new AhoyOnboarderCard("美食推荐", "不被时间和社会所束缚,幸福的填饱肚子的时候,短时间内变得随心所欲,变得“自由”不被谁打扰。毫不费神的吃东西这种孤高的行为,这种行为正是平等地赋予现代人的---最高的治愈!.", R.drawable.food);
  6. AhoyOnboarderCard ahoyOnboarderCard3 = new AhoyOnboarderCard("婚礼蜜月", "一生一次 永生难忘, 提供婚纱照, 蜜月随拍, 婚礼婚庆, 宝宝百天照.", R.drawable.chalk);
  7. AhoyOnboarderCard ahoyOnboarderCard4 = new AhoyOnboarderCard("投资移民", "私人订制的移民计划,帮助您在异国他乡安定生活, 为孩子提供最好的生活环境和教育, 走向人生巅峰.", R.drawable.house);
  8. AhoyOnboarderCard ahoyOnboarderCard5 = new AhoyOnboarderCard("电子商务及奥特莱斯供货", "MIAMI BELLE是公司为女性员工提供的一个福利性营业平台. 在广大女性员工的努力下,建立MIAMI BELLE品牌并在线销售该品牌产品.", R.drawable.wallet);
  9. AhoyOnboarderCard ahoyOnboarderCard6 = new AhoyOnboarderCard("美国游学", "世界著名大学游学夏令营, 为您的孩子提前跨进名校.", R.drawable.school);
  10. ahoyOnboarderCard1.setBackgroundColor(R.color.black_transparent);
  11. ahoyOnboarderCard2.setBackgroundColor(R.color.black_transparent);
  12. ahoyOnboarderCard3.setBackgroundColor(R.color.black_transparent);
  13. ahoyOnboarderCard4.setBackgroundColor(R.color.black_transparent);
  14. ahoyOnboarderCard5.setBackgroundColor(R.color.black_transparent);
  15. ahoyOnboarderCard6.setBackgroundColor(R.color.black_transparent);
  16. List<AhoyOnboarderCard> pages = new ArrayList<>();
  17. pages.add(ahoyOnboarderCard1);
  18. pages.add(ahoyOnboarderCard2);
  19. pages.add(ahoyOnboarderCard3);
  20. pages.add(ahoyOnboarderCard4);
  21. pages.add(ahoyOnboarderCard5);
  22. pages.add(ahoyOnboarderCard6);
  23. for (AhoyOnboarderCard page : pages) {
  24. page.setTitleColor(R.color.white);
  25. page.setDescriptionColor(R.color.grey_200);
  26. }
  27. setFinishButtonTitle("Get Started");
  28. showNavigationControls(true);
  29. //setGradientBackground();
  30. setImageBackground(R.drawable.download);
  31. Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
  32. //setFont(face);
  33. setInactiveIndicatorColor(R.color.grey_600);
  34. setActiveIndicatorColor(R.color.white);
  35. setOnboardPages(pages);
  36. }

front1front2front3
front4front5front6

  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_ahoy);
  5. setStatusBackgroundColor();
  6. hideActionBar();
  7. parentLayout = (RelativeLayout) findViewById(R.id.parent_layout);
  8. circleIndicatorView = (CircleIndicatorView) findViewById(R.id.circle_indicator_view);
  9. btnSkip = (TextView) findViewById(R.id.btn_skip);
  10. buttonsLayout = (FrameLayout) findViewById(R.id.buttons_layout);
  11. navigationControls = (FrameLayout) findViewById(R.id.navigation_layout);
  12. ivNext = (ImageView) findViewById(R.id.ivNext);
  13. ivPrev = (ImageView) findViewById(R.id.ivPrev);
  14. backgroundImage = (ImageView) findViewById(R.id.background_image);
  15. backgroundImageOverlay = (View) findViewById(R.id.background_image_overlay);
  16. vpOnboarderPager = (ViewPager) findViewById(R.id.vp_pager);
  17. vpOnboarderPager.addOnPageChangeListener(this);
  18. btnSkip.setOnClickListener(this);
  19. ivPrev.setOnClickListener(this);
  20. ivNext.setOnClickListener(this);
  21. hideFinish(false);
  22. fadeOut(ivPrev, false);
  23. }
  1. @Override
  2. public void onClick(View v) {
  3. int i = v.getId();
  4. boolean isInFirstPage = vpOnboarderPager.getCurrentItem() == 0;
  5. boolean isInLastPage = vpOnboarderPager.getCurrentItem() == ahoyOnboarderAdapter.getCount() - 1;
  6. if (i == R.id.btn_skip && isInLastPage) {
  7. onFinishButtonPressed();
  8. } else if (i == R.id.ivPrev && !isInFirstPage) {
  9. vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() - 1);
  10. } else if (i == R.id.ivNext && !isInLastPage) {
  11. vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() + 1);
  12. }
  13. }
  1. private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
  2. if (mGoogleApiClient.isConnected()) {
  3. Log.i(TAG, "Starting autocomplete query for: " + constraint);
  4. PendingResult<AutocompletePredictionBuffer> results =
  5. Places.GeoDataApi
  6. .getAutocompletePredictions(mGoogleApiClient,
  7. constraint.toString(), mBounds, mPlaceFilter);
  8. AutocompletePredictionBuffer autocompletePredictions = results
  9. .await(60, TimeUnit.SECONDS);
  10. final Status status = autocompletePredictions.getStatus();
  11. if (!status.isSuccess()) {
  12. Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
  13. Toast.LENGTH_SHORT).show();
  14. Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString());
  15. autocompletePredictions.release();
  16. return null;
  17. }
  18. Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
  19. + " predictions.");
  20. return DataBufferUtils.freezeAndClose(autocompletePredictions);
  21. }
  22. Log.e(TAG, "Google API client is not connected for autocomplete query.");
  23. return null;
  24. }

Login

  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context.getApplicationContext());
  5. if(status == ConnectionResult.SUCCESS) {
  6. //OK
  7. }else if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
  8. Toast.makeText(context,"please udpate your google play service",Toast.LENGTH_SHORT).show();
  9. }
  10. mGoogleApiClient = new GoogleApiClient.Builder(context)
  11. //.enableAutoManage(activity, 0 /* clientId */, this)
  12. .addApi(Places.GEO_DATA_API)
  13. .addConnectionCallbacks(this)
  14. .addOnConnectionFailedListener(this)
  15. // .addApi(LocationServices.API)
  16. .build();
  17. }
  18. @Override
  19. public void onConnectionFailed(ConnectionResult connectionResult) {
  20. Log.e(TAG, "onConnectionFailed: ConnectionResult.getErrorCode() = "
  21. + connectionResult.getErrorCode());
  22. // TODO(Developer): Check error code and notify the user of error state and resolution.
  23. Toast.makeText(context,
  24. "Failed to connect to Google geo API Client: Error " + connectionResult.getErrorCode(),
  25. Toast.LENGTH_SHORT).show();
  26. }

Detail view of Traveling plan View

butterknife

  1. public class MainActivity extends AppCompatActivity implements OnItemSelectedListener,
  2. NavigationView.OnNavigationItemSelectedListener {
  3. ...
  4. @BindView(R.id.drawer_layout)
  5. DrawerLayout drawerLayout;
  6. @BindView(R.id.navigation_view)
  7. NavigationView navigationView;
  8. @BindView(R.id.coordinator_layout)
  9. CoordinatorLayout coordinatorLayout;
  10. @BindView(R.id.toolbar)
  11. Toolbar toolbar;
  12. @Nullable
  13. @BindView(R.id.movie_detail_container)
  14. ScrollView movieDetailContainer;
  15. @Nullable
  16. @BindView(R.id.fab)
  17. FloatingActionButton fab;
  18. ...
  19. protected void onCreate() {
  20. ...
  21. ButterKnife.bind(this);
  22. ...
  23. }
  24. ...
  25. }

Retrofit+RxJava+Dagger2

  1. public static TheCitiesDbService getInstance(Context context) {
  2. synchronized (TheCitiesDbService.class) {
  3. if (instance == null) {
  4. Retrofit retrofit = new Retrofit.Builder()
  5. .baseUrl(BASE_URL)
  6. .addConverterFactory(GsonConverterFactory.create())
  7. .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
  8. .client(getClient(context))
  9. .build();
  10. instance = retrofit.create(TheCitiesDbService.class);
  11. }
  12. }
  13. return instance;
  14. }
  1. public interface TheCitiesDbService {
  2. @GET("city/{id}/videos")
  3. Observable<CitiesVideosResponse> getCityVideos(@Path("id") long cityId);
  4. @GET("city/{id}/reviews")
  5. Observable<CityReviewsResponse> getCityReviews(@Path("id") long cityId);
  6. @GET("discover/city")
  7. Observable<DiscoverResponse<City>> discovercities(@Query("sort_by") String sortBy, @Query("page") Integer page);
  8. }

RxAndroid/RxJava

  1. private void callDiscoverCities(String sort, @Nullable Integer page) {
  2. TheCitieDbService service = TheCitieDbClient.getInstance(context);
  3. service.discoverCities(sort, page)
  4. .subscribeOn(Schedulers.newThread())
  5. .doOnNext(discoverCitiesResponse -> clearCitiesSortTableIfNeeded(discoverCitiesResponse))
  6. .doOnNext(discoverCitiesResponse -> logResponse(discoverCitiesResponse))
  7. .map(discoverCitiesResponse -> discoverCitiesResponse.getResults())
  8. .flatMap(Cities -> Observable.from(Cities))
  9. .map(Citie -> saveCitie(Citie))
  10. .map(CitieUri -> CitiesContract.CitieEntry.getIdFromUri(CitieUri))
  11. .doOnNext(CitieId -> saveCitieReference(CitieId))
  12. .observeOn(AndroidSchedulers.mainThread())
  13. .subscribe(new Subscriber<Long>() {
  14. @Override
  15. public void onCompleted() {
  16. loading = false;
  17. sendUpdateFinishedBroadcast(true);
  18. }
  19. @Override
  20. public void onError(Throwable e) {
  21. loading = false;
  22. sendUpdateFinishedBroadcast(false);
  23. }
  24. @Override
  25. public void onNext(Long aLong) {
  26. // do nothing
  27. }
  28. });
  29. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注