Android Open Source - Material Button Fragment






From Project

Back to project page Material.

License

The source code is released under:

Apache License

If you think the Android project Material listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rey.material.demo;
//from w  ww .  jav a 2  s.  c o  m
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.rey.material.drawable.RevealDrawable;
import com.rey.material.view.Button;

public class ButtonFragment extends Fragment{

  public static ButtonFragment newInstance(){
    ButtonFragment fragment = new ButtonFragment();
    
    return fragment;
  }

  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_button, container, false);
    
    Button bt_flat = (Button)v.findViewById(R.id.button_bt_flat);
    Button bt_flat_color = (Button)v.findViewById(R.id.button_bt_flat_color);
    Button bt_flat_wave = (Button)v.findViewById(R.id.button_bt_flat_wave);
    Button bt_flat_wave_color = (Button)v.findViewById(R.id.button_bt_flat_wave_color);
    Button bt_raise = (Button)v.findViewById(R.id.button_bt_raise);
    Button bt_raise_color = (Button)v.findViewById(R.id.button_bt_raise_color);
    Button bt_raise_wave = (Button)v.findViewById(R.id.button_bt_raise_wave);
    Button bt_raise_wave_color = (Button)v.findViewById(R.id.button_bt_raise_wave_color);
    Button bt_float = (Button)v.findViewById(R.id.button_bt_float);
    Button bt_float_color = (Button)v.findViewById(R.id.button_bt_float_color);
    Button bt_float_wave = (Button)v.findViewById(R.id.button_bt_float_wave);
    Button bt_float_wave_color = (Button)v.findViewById(R.id.button_bt_float_wave_color);
                  
    View.OnClickListener listener = new View.OnClickListener() {
      
      @Override
      public void onClick(View v) {
        Toast.makeText(getActivity(), "Button Clicked!\nEvent's fired when in anim end.", Toast.LENGTH_SHORT).show();        
      }
    };
    
    View.OnClickListener listener_delay = new View.OnClickListener() {
      
      @Override
      public void onClick(View v) {
        Toast.makeText(getActivity(), "Button Clicked!\nEvent's fired when out anim end.", Toast.LENGTH_SHORT).show();      
      }
    };
    
    bt_flat.setOnClickListener(listener);
    bt_flat_wave.setOnClickListener(listener);
    bt_raise.setOnClickListener(listener);
    bt_raise_wave.setOnClickListener(listener);
    bt_float.setOnClickListener(listener);
    bt_float_wave.setOnClickListener(listener);
    
    bt_flat_color.setOnClickListener(listener_delay);
    bt_flat_wave_color.setOnClickListener(listener_delay);
    bt_raise_color.setOnClickListener(listener_delay);
    bt_raise_wave_color.setOnClickListener(listener_delay);
    bt_float_color.setOnClickListener(listener_delay);
    bt_float_wave_color.setOnClickListener(listener_delay);
        
//    Spinner spn = (Spinner)v.findViewById(R.id.button_spn);
//    spn.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.row_spn, R.id.row_spn_tv, new String[]{"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9"}));
    
    final int color1 = 0xFF0000FF;
    final int color2 = 0x00FF0000;
    final int duration = 2000;
    final boolean out = true;
    
    final View a = v.findViewById(R.id.button_v);
    final RevealDrawable drawable = new RevealDrawable(color1);
    a.setBackgroundDrawable(drawable);
    
    a.setOnClickListener(new View.OnClickListener() {
      
      @Override
      public void onClick(View v) {
        RevealDrawable.ColorChangeTask task1 = new RevealDrawable.ColorChangeTask(color1, duration, null, a.getWidth() / 2f, a.getHeight() / 2f, out);
        RevealDrawable.ColorChangeTask task2 = new RevealDrawable.ColorChangeTask(color2, duration, null, a.getWidth() / 2f, a.getHeight() / 2f, out);
        
        if(drawable.getCurColor() == color1)
          drawable.changeColor(task2, task1, task2);
        else
          drawable.changeColor(task1, task2, task1);
      }
      
    });
    
    return v;
  }

  @Override
  public void onPause() {
    super.onPause();
  }

  @Override
  public void onResume() {
    super.onResume();
  }
  
}




Java Source Code List

com.rey.material.ApplicationTest.java
com.rey.material.demo.ButtonFragment.java
com.rey.material.demo.MainActivity.java
com.rey.material.demo.ProgressFragment.java
com.rey.material.demo.SnackbarFragment.java
com.rey.material.demo.SwitchesFragment.java
com.rey.material.demo.TextfieldFragment.java
com.rey.material.drawable.ArrowDrawable.java
com.rey.material.drawable.BlankDrawable.java
com.rey.material.drawable.CheckBoxDrawable.java
com.rey.material.drawable.CircularProgressDrawable.java
com.rey.material.drawable.DividerDrawable.java
com.rey.material.drawable.LineMorphingDrawable.java
com.rey.material.drawable.LinearProgressDrawable.java
com.rey.material.drawable.NavigationDrawerDrawable.java
com.rey.material.drawable.RadioButtonDrawable.java
com.rey.material.drawable.RevealDrawable.java
com.rey.material.drawable.RippleDrawable.java
com.rey.material.drawable.ToolbarRippleDrawable.java
com.rey.material.util.ColorUtil.java
com.rey.material.util.ThemeUtil.java
com.rey.material.util.ViewUtil.java
com.rey.material.view.Button.java
com.rey.material.view.CheckBox.java
com.rey.material.view.CheckedTextView.java
com.rey.material.view.CompoundButton.java
com.rey.material.view.EditText.java
com.rey.material.view.FloatingActionButton.java
com.rey.material.view.ListPopupWindow.java
com.rey.material.view.ListView.java
com.rey.material.view.PopupWindow.java
com.rey.material.view.ProgressView.java
com.rey.material.view.RadioButton.java
com.rey.material.view.RippleManager.java
com.rey.material.view.SnackBar.java
com.rey.material.view.Spinner.java
com.rey.material.view.Switch.java
com.rey.material.view.TabPageIndicator.java
com.rey.material.view.TextView.java