@Override
  public void onScrollChanged(int deltaX, int deltaY) {
    // Reposition the header bar -- it's normally anchored to the top of the content,
    // but locks to the top of the screen on scroll
    int scrollY = mScrollView.getScrollY();

    float newTop = Math.max(mPhotoHeightPixels, scrollY);
    mHeaderBox.setTranslationY(newTop);
    mAddScheduleButtonContainer.setTranslationY(
        newTop + mHeaderHeightPixels - mAddScheduleButtonContainerHeightPixels / 2);

    float gapFillProgress = 1;
    if (mPhotoHeightPixels != 0) {
      gapFillProgress =
          Math.min(Math.max(UIUtils.getProgress(scrollY, 0, mPhotoHeightPixels), 0), 1);
    }

    ViewCompat.setElevation(mHeaderBox, gapFillProgress * mMaxHeaderElevation);
    ViewCompat.setElevation(
        mAddScheduleButtonContainer, gapFillProgress * mMaxHeaderElevation + mFABElevation);
    ViewCompat.setElevation(
        mAddScheduleButton, gapFillProgress * mMaxHeaderElevation + mFABElevation);

    // Move background photo (parallax effect)
    mPhotoViewContainer.setTranslationY(scrollY * 0.5f);
  }
 @Override
 protected void setViewPageData() {
   super.setViewPageData();
   viewPager.setAdapter(new MyDetailPagerAdapter(this, getSupportFragmentManager()));
   tabs.setViewPager(viewPager);
   ViewCompat.setElevation(tabs, 0);
   ViewCompat.setElevation(findViewById(R.id.appbarLayout), 0);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.conversations);

    gcm = Gcm.getInstance(getApplicationContext());
    billing = Billing.getInstance(getApplicationContext());
    database = Database.getInstance(getApplicationContext());
    preferences = Preferences.getInstance(getApplicationContext());

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation));
    setSupportActionBar(toolbar);

    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    adapter = new ConversationsRecyclerViewAdapter(this, layoutManager);
    recyclerView = (RecyclerView) findViewById(R.id.list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);

    actionMode = null;
    actionModeEnabled = false;

    SwipeRefreshLayout swipeRefreshLayout =
        (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            preFullUpdate();
          }
        });
    swipeRefreshLayout.setColorSchemeResources(R.color.accent);

    ImageButton button = (ImageButton) findViewById(R.id.new_button);
    ViewCompat.setElevation(button, getResources().getDimension(R.dimen.fab_elevation));
    button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!preferences.getEmail().equals("")
                && !preferences.getPassword().equals("")
                && !preferences.getDid().equals("")) {
              Intent intent = new Intent(conversationsActivity, NewConversationActivity.class);
              startActivity(intent);
            }
          }
        });

    SynchronizationIntervalReceiver.setupSynchronizationInterval(getApplicationContext());
  }
Example #4
0
 @Override
 public void onScroll(int l, int t, int oldl, int oldt) {
   int height = mHeader.getMeasuredHeight() - mToolbar.getMeasuredHeight();
   Drawable drawable = mToolbarContainer.getBackground();
   int alpha = 255 * (Math.min(Math.max(t, 0), height)) / height;
   drawable.setAlpha(alpha);
   if (alpha >= 255) {
     ViewCompat.setElevation(mToolbarContainer, mElevation);
     ViewCompat.setElevation(mHeader, 0);
   } else {
     ViewCompat.setElevation(mToolbarContainer, 0);
     ViewCompat.setElevation(mHeader, mElevation);
   }
 }
  public CircleImageViewSupport(Context context, int color, final float radius) {
    super(context);
    final float density = getContext().getResources().getDisplayMetrics().density;
    final int diameter = (int) (radius * density * 2);
    final int shadowYOffset = (int) (density * Y_OFFSET);
    final int shadowXOffset = (int) (density * X_OFFSET);

    mShadowRadius = (int) (density * SHADOW_RADIUS);

    ShapeDrawable circle;
    if (elevationSupported()) {
      circle = new ShapeDrawable(new OvalShape());
      ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
    } else {
      OvalShape oval = new OvalShadow(mShadowRadius, diameter);
      circle = new ShapeDrawable(oval);
      ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint());
      circle
          .getPaint()
          .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
      final int padding = mShadowRadius;
      // set padding so the inner image sits correctly within the shadow.
      setPadding(padding, padding, padding, padding);
    }
    circle.getPaint().setColor(color);
    setBackgroundDrawable(circle);
  }
Example #6
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_group, container, false);

    final Context context = this.getActivity();

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.library_fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            new AlertDialog.Builder(context)
                .setTitle("Create group")
                .setMessage(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
                .setNegativeButton("Cancel", null)
                .setPositiveButton("Create", null)
                .show();
          }
        });

    ViewCompat.setElevation(rootView, 50);
    return rootView;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_my_tba, container, false);
    mViewPager = (ViewPager) v.findViewById(R.id.my_tba_pager);
    // Make this ridiculously big
    mViewPager.setOffscreenPageLimit(50);
    mViewPager.setPageMargin(Utilities.getPixelsFromDp(getActivity(), 16));
    mTabs = (SlidingTabs) v.findViewById(R.id.my_tba_tabs);
    ViewCompat.setElevation(mTabs, getResources().getDimension(R.dimen.toolbar_elevation));

    /**
     * Fix for really strange bug. Menu bar items wouldn't appear only when navigated to from
     * 'Events' in the nav drawer Bug is some derivation of this:
     * https://code.google.com/p/android/issues/detail?id=29472 So set the view pager's adapter in
     * another thread to avoid a race condition, or something.
     */
    mViewPager.post(
        () -> {
          mViewPager.setAdapter(new MyTBAFragmentPagerAdapter(getChildFragmentManager()));
          mTabs.setViewPager(mViewPager);
        });

    return v;
  }
  private void loadProjectData() {
    ViewUtils.setTextOrClear(
        binding.projectSubtitleTv,
        getString(R.string.project_details_made_by, project.getAuthorName()));
    if (LUtils.hasL()) {
      animateAlphaAfterTransition(binding.projectSubtitleTv);
    }

    binding.projectBackingProgress.setText(
        project.isFunded() ? R.string.funded : R.string.backing_in_progress);

    binding.projectItemBigProgressSb.setProgress((int) project.getPercentProgress());
    ProjectsAdapter.setProjectDetailsInfo(
        binding.projectItemBigGatheredMoneyTv,
        binding.projectItemBigPledgedOfTv,
        binding.projectItemBigDaysLeft,
        binding.projectItemTimeLeftTypeTv,
        project);

    // TODO: animate elevation on scroll.
    ViewCompat.setElevation(
        binding.detailsContainer, ViewUtils.convertDpToPixel(4, ProjectDetailsActivity.this));

    loadProjectPhoto();
  }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie);
    ButterKnife.bind(this);

    if (toolbar != null) {
      ViewCompat.setElevation(toolbar, 8);
      toolbar.setNavigationOnClickListener(view -> finish());

      ActionBar ab = getSupportActionBar();
      if (ab != null) {
        ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setDisplayShowHomeEnabled(true);
      }
    }
    Movie movie = getIntent().getParcelableExtra(EXTRA_MOVIE);

    ViewCompat.setTransitionName(movieDetailsContainer, TRANSITION_SHARED_ELEMENT);
    if (savedInstanceState == null) {
      MovieFragment fragment = MovieFragment.newInstance(movie);
      getSupportFragmentManager()
          .beginTransaction()
          .replace(R.id.movie_details_container, fragment, MOVIE_FRAGMENT_TAG)
          .commit();
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_results);

    ((TBAAndroid) getApplication()).getDbComponent().inject(this);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation));
    setSupportActionBar(toolbar);

    /* Report activity start to Analytics */
    new AnalyticsActions.ReportActivityStart(this).run();

    resultsList = (ListView) findViewById(R.id.results);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");

    query = getIntent().getStringExtra(QUERY);
    resultsType = getIntent().getIntExtra(RESULTS_TYPE, -1);
    if (query == null || resultsType == -1) {
      throw new IllegalArgumentException(
          "MoreSearchResultsActivity most be created with a mode and query string!");
    }

    String preparedQuery = Utilities.getPreparedQueryForSearch(query);

    Bundle loaderBundle = new Bundle();
    loaderBundle.putString(PREPARED_QUERY, preparedQuery);

    getSupportLoaderManager().restartLoader(resultsType, loaderBundle, this);
    switch (resultsType) {
      case TEAM_RESULTS:
        getSupportActionBar().setTitle(String.format(getString(R.string.teams_matching), query));
        break;
      case EVENT_RESULTS:
        getSupportActionBar().setTitle(String.format(getString(R.string.events_matching), query));
        break;
    }

    resultsList.setOnItemClickListener(
        (adapterView, view, position, id) -> {
          switch (resultsType) {
            case TEAM_RESULTS:
              TeamCursorAdapter teamAdapter = (TeamCursorAdapter) adapterView.getAdapter();
              String teamKey = teamAdapter.getKey(position);
              startActivity(ViewTeamActivity.newInstance(MoreSearchResultsActivity.this, teamKey));
              break;
            case EVENT_RESULTS:
              EventCursorAdapter eventAdapter = (EventCursorAdapter) adapterView.getAdapter();
              String eventKey = eventAdapter.getKey(position);
              startActivity(
                  ViewEventActivity.newInstance(MoreSearchResultsActivity.this, eventKey));
              break;
          }
        });
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
      mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }
    if (getBackground() == null && mCircleBackgroundEnabled) {
      final int shadowYOffset = (int) (density * Y_OFFSET);
      final int shadowXOffset = (int) (density * X_OFFSET);
      mShadowRadius = (int) (density * SHADOW_RADIUS);

      if (elevationSupported()) {
        mBgCircle = new ShapeDrawable(new OvalShape());
        ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
      } else {
        OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
        mBgCircle = new ShapeDrawable(oval);
        ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
        mBgCircle
            .getPaint()
            .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
        final int padding = (int) mShadowRadius;
        // set padding so the inner image sits correctly within the shadow.
        setPadding(padding, padding, padding, padding);
      }
      mBgCircle.getPaint().setColor(mBackGroundColor);
      setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    mProgressDrawable.setSizeParameters(
        mDiameter,
        mDiameter,
        mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
        mProgressStokeWidth,
        mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
        mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
    if (isShowArrow()) {
      mProgressDrawable.showArrowOnFirstStart(true);
      mProgressDrawable.setArrowScale(1f);
      mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    mProgressDrawable.setStartEndTrim(0f, 0.75f);
  }
Example #12
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_song_library, container, false);

    ListView listView = (ListView) rootView.findViewById(R.id.library_song_list);
    listView.setAdapter(new SongAdapter(getActivity()));

    // We add a listener to each item in the list
    // When pressed, opens info page to backstreet boys
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Intent intent = new Intent(getActivity(), SongInfoActivity.class);
            getActivity().startActivity(intent);
          }
        });

    final Context context = this.getActivity();
    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.library_fab);
    fab.attachToListView(listView);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            new AlertDialog.Builder(context)
                .setTitle("Sort songs")
                .setMessage(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
                .setNegativeButton("Cancel", null)
                .setPositiveButton("Sort", null)
                .show();
          }
        });

    ViewCompat.setElevation(rootView, 50);
    return rootView;
  }
 @Override
 public void onCreate(final Bundle icicle) {
   if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
   }
   super.onCreate(icicle);
   final int themeColor = getThemeColor();
   final int themeResId = getCurrentThemeResourceId();
   final String backgroundOption = getCurrentThemeBackgroundOption();
   mMainContent.setDrawColor(true);
   mMainContent.setDrawShadow(false);
   mMainContent.setColor(themeColor);
   ViewSupport.setBackground(
       mDoneCancelBar,
       ThemeUtils.getActionBarBackground(this, themeResId, themeColor, backgroundOption, true));
   ViewCompat.setElevation(mDoneCancelBar, ThemeUtils.getSupportActionBarElevation(this));
   final View windowOverlay = findViewById(R.id.window_overlay);
   ViewSupport.setBackground(
       windowOverlay, ThemeUtils.getNormalWindowContentOverlay(this, themeResId));
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the RecyclerView, and attach this adapter to it.
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_forecast);

    // Set the layout manager
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    View emptyView = rootView.findViewById(R.id.recyclerview_forecast_empty);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // The ForecastAdapter will take data from a source and
    // use it to populate the RecyclerView it's attached to.
    mForecastAdapter =
        new ForecastAdapter(
            getActivity(),
            new ForecastAdapter.ForecastAdapterOnClickHandler() {
              @Override
              public void onClick(Long date, ForecastAdapter.ForecastAdapterViewHolder vh) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity())
                    .onItemSelected(
                        WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                            locationSetting, date),
                        vh);
              }
            },
            emptyView,
            mChoiceMode);

    // specify an adapter (see also next example)
    mRecyclerView.setAdapter(mForecastAdapter);

    final View parallaxView = rootView.findViewById(R.id.parallax_bar);
    if (null != parallaxView) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mRecyclerView.addOnScrollListener(
            new RecyclerView.OnScrollListener() {
              @TargetApi(Build.VERSION_CODES.HONEYCOMB)
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                int max = parallaxView.getHeight();
                if (dy > 0) {
                  parallaxView.setTranslationY(
                      Math.max(-max, parallaxView.getTranslationY() - dy / 2));
                } else {
                  parallaxView.setTranslationY(
                      Math.min(0, parallaxView.getTranslationY() - dy / 2));
                }
              }
            });
      }
    }

    final AppBarLayout appbarView = (AppBarLayout) rootView.findViewById(R.id.appbar);
    if (null != appbarView) {
      ViewCompat.setElevation(appbarView, 0);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mRecyclerView.addOnScrollListener(
            new RecyclerView.OnScrollListener() {
              @TargetApi(Build.VERSION_CODES.LOLLIPOP)
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (0 == mRecyclerView.computeVerticalScrollOffset()) {
                  appbarView.setElevation(0);
                } else {
                  appbarView.setElevation(appbarView.getTargetElevation());
                }
              }
            });
      }
    }

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null) {
      mForecastAdapter.onRestoreInstanceState(savedInstanceState);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
  }
Example #15
0
  public IndicatableFFAB(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final View v = View.inflate(context, R.layout.view_indicatable_ffab, this);
    indicator = (ActionIndicatorView) v.findViewById(R.id.iffab_indicator);
    ffab = (FlingableFAB) v.findViewById(R.id.iffab_ffab);
    ViewCompat.setElevation(indicator, ffab.getCompatElevation());

    final TypedArray a =
        context.obtainStyledAttributes(
            attrs, R.styleable.IndicatableFFAB, defStyleAttr, R.style.Widget_FFAB_IndicatableFFAB);
    try {
      final Drawable fabIcon = a.getDrawable(R.styleable.IndicatableFFAB_fabIcon);
      ffab.setImageDrawable(fabIcon);
      final int fabTint = a.getColor(R.styleable.IndicatableFFAB_fabTint, NO_ID);
      if (fabTint != NO_ID) {
        ViewCompat.setBackgroundTintList(ffab, ColorStateList.valueOf(fabTint));
      }
      final int indicatorTint = a.getColor(R.styleable.IndicatableFFAB_indicatorTint, 0);
      indicator.setBackgroundColor(indicatorTint);
      indicatorMargin =
          a.getDimensionPixelSize(R.styleable.IndicatableFFAB_marginFabToIndicator, 0);
    } finally {
      a.recycle();
    }

    ffab.setOnTouchListener(
        new OnTouchListener() {
          private MotionEvent old;

          @Override
          public boolean onTouch(View view, MotionEvent motionEvent) {
            final int action = motionEvent.getAction();
            if (action == MotionEvent.ACTION_DOWN) {
              old = MotionEvent.obtain(motionEvent);
              onStart();
              return false;
            }
            final Direction direction = Direction.getDirection(old, motionEvent);
            if (action == MotionEvent.ACTION_MOVE) {
              onMoving(direction);
            } else if (action == MotionEvent.ACTION_UP) {
              old.recycle();
              onFling(view.getHandler());
            }
            return false;
          }

          private Direction prevSelected = Direction.UNDEFINED;

          public void onStart() {
            indicator.onActionLeave(prevSelected);
            prevSelected = Direction.UNDEFINED;
            indicator.setVisibility(View.VISIBLE);
          }

          public void onMoving(Direction direction) {
            if (prevSelected == direction) {
              return;
            }
            indicator.onActionLeave(prevSelected);
            if (isDirectionEnabled(direction)) {
              indicator.onActionSelected(direction);
            }
            prevSelected = direction;
          }

          private boolean isDirectionEnabled(Direction direction) {
            for (Direction d : enableDirections) {
              if (d == direction) {
                return true;
              }
            }
            return false;
          }

          public void onFling(Handler handler) {
            handler.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    indicator.setVisibility(View.INVISIBLE);
                  }
                },
                200);
          }
        });

    if (isInEditMode()) {
      indicator.setVisibility(VISIBLE);
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    String locationSetting = Utility.getPreferredLocation(getActivity());

    // Sort order:  Ascending, by date.
    //        String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
    //        Uri weatherForLocationUri =
    // WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
    //                locationSetting, System.currentTimeMillis());

    //        Cursor cur = getActivity().getContentResolver().query(weatherForLocationUri,
    //                null, null, null, sortOrder);

    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.

    // However, we cannot use FLAG_AUTO_REQUERY since it is deprecated, so we will end
    // up with an empty list the first time we run.

    //       // The CursorAdapter will take data from our cursor and populate the ListView.
    //      mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    //// The ForecastAdapter will take data from a source and
    //               // use it to populate the RecyclerView it's attached to.
    //        mForecastAdapter = new ForecastAdapter(getActivity());

    rootView = inflater.inflate(R.layout.fragment_main, container, false);
    //        mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    //        View emptyView = rootView.findViewById(R.id.listview_forecast_empty);
    //        mListView.setEmptyView(emptyView);
    //        mListView.setAdapter(mForecastAdapter);

    // Get a reference to the RecyclerView, and attach this adapter to it.
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_forecast);
    // Set the layout manager
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    View emptyView = rootView.findViewById(R.id.recyclerview_forecast_empty);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // The ForecastAdapter will take data from a source and
    // use it to populate the RecyclerView it's attached to.
    mForecastAdapter =
        new ForecastAdapter(
            getActivity(),
            new ForecastAdapter.ForecastAdapterOnClickHandler() {
              @Override
              public void onClick(Long date, ForecastAdapter.ForecastAdapterViewHolder vh) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity())
                    .onItemSelected(
                        WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                            locationSetting, date),
                        vh);
                // I could have sent the position back directly instead of the ViewHolder
                mPosition = vh.getAdapterPosition();
              }
            },
            emptyView,
            mChoiceMode);

    // specify an adapter (see also next example)
    mRecyclerView.setAdapter(mForecastAdapter);

    final View parallaxView = rootView.findViewById(R.id.parallax_bar);
    if (null != parallaxView) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mRecyclerView.addOnScrollListener(
            new RecyclerView.OnScrollListener() {
              @TargetApi(Build.VERSION_CODES.HONEYCOMB)
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                int max = parallaxView.getHeight();
                if (dy > 0) {
                  parallaxView.setTranslationY(
                      Math.max(-max, parallaxView.getTranslationY() - dy / 2));
                } else {
                  parallaxView.setTranslationY(
                      Math.min(0, parallaxView.getTranslationY() - dy / 2));
                }
              }
            });
      }
    }

    final AppBarLayout appbarView = (AppBarLayout) rootView.findViewById(R.id.appbar);
    if (null != appbarView) {
      ViewCompat.setElevation(appbarView, 0);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mRecyclerView.addOnScrollListener(
            new RecyclerView.OnScrollListener() {
              @TargetApi(Build.VERSION_CODES.LOLLIPOP)
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (0 == mRecyclerView.computeVerticalScrollOffset()) {
                  appbarView.setElevation(0);
                } else {
                  appbarView.setElevation(appbarView.getTargetElevation());
                }
              }
            });
      }
    }

    //        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    //
    //            @Override
    //            public void onItemClick(AdapterView adapterView, View view, int position, long l)
    // {
    //                // CursorAdapter returns a cursor at the correct position for getItem(), or
    // null
    //                // if it cannot seek to that position.
    //                Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
    //                if (cursor != null) {
    //                    String locationSetting = Utility.getPreferredLocation(getActivity());
    //
    //                    ((Callback) getActivity())
    //
    // .onItemSelected(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
    //                                    locationSetting, cursor.getLong(COL_WEATHER_DATE)
    //                            ));
    //
    //                    mPosition = position;
    //                }
    //            }
    //        });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null) {
      if (savedInstanceState.containsKey(SELECTED_KEY)) {
        // The Recycler View probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
      }
      mForecastAdapter.onRestoreInstanceState(savedInstanceState);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
  }
Example #17
0
  public MaterialTabHost(Context context, AttributeSet attrs) {
    super(context, attrs);

    inflater = LayoutInflater.from(context);

    TypedValue outValue = new TypedValue();
    Resources.Theme theme = context.getTheme();
    // use ?attr/colorPrimary as background color
    // theme.resolveAttribute(R.attr.colorPrimary, outValue, true);
    // setBackgroundColor(outValue.data);

    // use ?attr/colorControlActivated as default indicator color
    // theme.resolveAttribute(R.attr.colorControlActivated, outValue, true);
    // colorControlActivated = outValue.data;
    setBackgroundColor(0xff0CACF4);
    colorControlActivated = 0xffBEEAFC;

    TypedArray a =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaterialTabHost, 0, 0);
    int indicatorColor =
        a.getColor(R.styleable.MaterialTabHost_colorTabIndicator, colorControlActivated);
    a.recycle();

    // ColorDrawable on 2.x does not use getBounds() so use ShapeDrawable
    indicator = new ShapeDrawable();
    indicator.setColorFilter(indicatorColor, PorterDuff.Mode.SRC_ATOP);

    Resources res = context.getResources();
    indicatorHeight = res.getDimensionPixelSize(R.dimen.mth_tab_indicator_height);
    leftOffset = res.getDimensionPixelSize(R.dimen.mth_tab_left_offset);
    // int tabHeight = res.getDimensionPixelSize(R.dimen.mth_tab_height);

    tabWidget = new TabWidget(context);
    tabWidget.setLayoutParams(
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    tabWidget.setId(android.R.id.tabs);
    tabWidget.setStripEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      tabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }
    addView(tabWidget);

    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(new LayoutParams(0, 0));
    fl.setId(android.R.id.tabcontent);
    addView(fl);

    setup();

    setOnTabChangedListener(
        new TabHost.OnTabChangeListener() {
          @Override
          public void onTabChanged(String tabId) {
            if (listener != null) {
              listener.onTabSelected(Integer.valueOf(tabId));
            }
          }
        });

    float density = getResources().getDisplayMetrics().density;

    // set elevation for App bar
    // http://www.google.com/design/spec/what-is-material/objects-in-3d-space.html#objects-in-3d-space-elevation
    ViewCompat.setElevation(this, APP_TAB_ELEVATION * density);
  }