• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 package com.example.android.cardview;
18 
19 import android.app.Fragment;
20 import android.os.Bundle;
21 import android.support.v7.widget.CardView;
22 import android.util.Log;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.SeekBar;
27 
28 /**
29  * Fragment that demonstrates how to use CardView.
30  */
31 public class CardViewFragment extends Fragment {
32 
33     private static final String TAG = CardViewFragment.class.getSimpleName();
34 
35     /** The CardView widget. */
36     //@VisibleForTesting
37     CardView mCardView;
38 
39     /**
40      * SeekBar that changes the cornerRadius attribute for the {@link #mCardView} widget.
41      */
42     //@VisibleForTesting
43     SeekBar mRadiusSeekBar;
44 
45     /**
46      * SeekBar that changes the Elevation attribute for the {@link #mCardView} widget.
47      */
48     //@VisibleForTesting
49     SeekBar mElevationSeekBar;
50 
51     /**
52      * Use this factory method to create a new instance of
53      * this fragment using the provided parameters.
54      *
55      * @return A new instance of fragment NotificationFragment.
56      */
newInstance()57     public static CardViewFragment newInstance() {
58         CardViewFragment fragment = new CardViewFragment();
59         fragment.setRetainInstance(true);
60         return fragment;
61     }
62 
CardViewFragment()63     public CardViewFragment() {
64         // Required empty public constructor
65     }
66 
67     @Override
onCreate(Bundle savedInstanceState)68     public void onCreate(Bundle savedInstanceState) {
69         super.onCreate(savedInstanceState);
70     }
71 
72     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)73     public View onCreateView(LayoutInflater inflater, ViewGroup container,
74                              Bundle savedInstanceState) {
75         // Inflate the layout for this fragment
76         return inflater.inflate(R.layout.fragment_card_view, container, false);
77     }
78 
79     @Override
onViewCreated(View view, Bundle savedInstanceState)80     public void onViewCreated(View view, Bundle savedInstanceState) {
81         super.onViewCreated(view, savedInstanceState);
82         mCardView = (CardView) view.findViewById(R.id.cardview);
83         mRadiusSeekBar = (SeekBar) view.findViewById(R.id.cardview_radius_seekbar);
84         mRadiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
85             @Override
86             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
87                 Log.d(TAG, String.format("SeekBar Radius progress : %d", progress));
88                 mCardView.setRadius(progress);
89             }
90             @Override
91             public void onStartTrackingTouch(SeekBar seekBar) {
92                 //Do nothing
93             }
94 
95             @Override
96             public void onStopTrackingTouch(SeekBar seekBar) {
97                 //Do nothing
98             }
99         });
100 
101         mElevationSeekBar = (SeekBar) view.findViewById(R.id.cardview_elevation_seekbar);
102         mElevationSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
103             @Override
104             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
105                 Log.d(TAG, String.format("SeekBar Elevation progress : %d", progress));
106                 mCardView.setElevation(progress);
107             }
108             @Override
109             public void onStartTrackingTouch(SeekBar seekBar) {
110                 //Do nothing
111             }
112 
113             @Override
114             public void onStopTrackingTouch(SeekBar seekBar) {
115                 //Do nothing
116             }
117         });
118     }
119 }
120 
121