Android Open Source - nxt-remote-controller Snack Bar






From Project

Back to project page nxt-remote-controller.

License

The source code is released under:

MIT License

If you think the Android project nxt-remote-controller 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.gc.materialdesign.widgets;
//  ww  w.java 2 s .  com
import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.gc.materialdesign.R;
import com.gc.materialdesign.views.ButtonFlat;

public class SnackBar extends Dialog{
  
  String text;
  float textSize = 14;//Roboto Regular14sp 
  String buttonText;
  View.OnClickListener onClickListener;
  Activity activity;
  View view;
  ButtonFlat button;
  int backgroundSnackBar = Color.parseColor("#333333");
  int backgroundButton = Color.parseColor("#1E88E5");
  
  OnHideListener onHideListener;
  // Timer
  private boolean mIndeterminate = false;
  private int mTimer = 3 * 1000;
  
  // With action button
  public SnackBar(Activity activity, String text, String buttonText, View.OnClickListener onClickListener) {
    super(activity, android.R.style.Theme_Translucent);
    this.activity = activity;
    this.text = text;
    this.buttonText = buttonText;
    this.onClickListener = onClickListener;
  }
  
  // Only text
  public SnackBar(Activity activity, String text) {
    super(activity, android.R.style.Theme_Translucent);
    this.activity = activity;
    this.text = text;
  }
  
  @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.snackbar);
      setCanceledOnTouchOutside(false);
      ((TextView)findViewById(R.id.text)).setText(text); 
      ((TextView)findViewById(R.id.text)).setTextSize(textSize); //set textSize
    button = (ButtonFlat) findViewById(R.id.buttonflat);
    if(text == null || onClickListener == null){
      button.setVisibility(View.GONE);
    }else{
      button.setText(buttonText);
      button.setBackgroundColor(backgroundButton);
      
      button.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
          dismiss();
          onClickListener.onClick(v);
        }
      });
    }
    view = findViewById(R.id.snackbar);
    view.setBackgroundColor(backgroundSnackBar);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    return activity.dispatchTouchEvent(event);
  }
  
  @Override
  public void onBackPressed() {
  }
  
  @Override
  public void show() {
    super.show();
    view.setVisibility(View.VISIBLE);
    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.snackbar_show_animation));
    if (!mIndeterminate) {
        dismissTimer.start();
    }
  }
  
  // Dismiss timer 
  Thread dismissTimer = new Thread(new Runnable() {
    
    @Override
    public void run() {
      try {
        Thread.sleep(mTimer);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      handler.sendMessage(new Message());
    }
  });
  
  Handler handler = new Handler(new Handler.Callback() {
    
    @Override
    public boolean handleMessage(Message msg) {
       if(onHideListener != null) {
         onHideListener.onHide();
       }
      dismiss();
      return false;
    }
  });
  
  /**
   * @author Jack Tony
   */
  @Override
  public void dismiss() {
    Animation anim = AnimationUtils.loadAnimation(activity, R.anim.snackbar_hide_animation);
    anim.setAnimationListener(new AnimationListener() {
      
      @Override
      public void onAnimationStart(Animation animation) {
      }
      
      @Override
      public void onAnimationRepeat(Animation animation) {
      }
      
      @Override
      public void onAnimationEnd(Animation animation) {
        SnackBar.super.dismiss();
      }
    });
    view.startAnimation(anim);
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO ??????????
     if (keyCode == KeyEvent.KEYCODE_BACK )  {
       dismiss();
     }
    return super.onKeyDown(keyCode, event);
  }
  
  public void setMessageTextSize(float size) {
    textSize = size;
  }
  
  public void setIndeterminate(boolean indeterminate) {
          mIndeterminate = indeterminate;
  }
  
  public boolean isIndeterminate() {
    return mIndeterminate;
  }

  public void setDismissTimer(int time) {
    mTimer = time;
  }
  
  public int getDismissTimer() {
    return mTimer;
  }
  
  /**
   * Change background color of SnackBar
   * @param color
   */
  public void setBackgroundSnackBar(int color){
    backgroundSnackBar = color;
    if(view != null)
      view.setBackgroundColor(color);
  }
  
  /**
   * Chage color of FlatButton in Snackbar
   * @param color
   */
  public void setColorButton(int color){
    backgroundButton = color;
    if(button != null)
      button.setBackgroundColor(color);
  }
  
  /**
   * This event start when snackbar dismish without push the button
   * @author Navas
   *
   */
  public interface OnHideListener{
    public void onHide();
  }
  
  public void setOnhideListener(OnHideListener onHideListener){
    this.onHideListener = onHideListener;
  }
}




Java Source Code List

.OldPadControllerFragment.java
com.andexert.library.ApplicationTest.java
com.andexert.library.RippleView.java
com.andexert.rippleeffect.ApplicationTest.java
com.andexert.rippleeffect.CustomAdapter.java
com.andexert.rippleeffect.MainActivity.java
com.andexert.rippleeffect.OnTapListener.java
com.gc.materialdesign.utils.Utils.java
com.gc.materialdesign.views.ButtonFlat.java
com.gc.materialdesign.views.ButtonFloatSmall.java
com.gc.materialdesign.views.ButtonFloat.java
com.gc.materialdesign.views.ButtonIcon.java
com.gc.materialdesign.views.ButtonRectangle.java
com.gc.materialdesign.views.Button.java
com.gc.materialdesign.views.Card.java
com.gc.materialdesign.views.CheckBox.java
com.gc.materialdesign.views.CustomView.java
com.gc.materialdesign.views.LayoutRipple.java
com.gc.materialdesign.views.ProgressBarCircularIndeterminate.java
com.gc.materialdesign.views.ProgressBarDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminate.java
com.gc.materialdesign.views.RippleView.java
com.gc.materialdesign.views.ScrollView.java
com.gc.materialdesign.views.Slider.java
com.gc.materialdesign.views.Switch.java
com.gc.materialdesign.widgets.ColorSelector.java
com.gc.materialdesign.widgets.Dialog.java
com.gc.materialdesign.widgets.SnackBar.java
git.egatuts.nxtremotecontroller.ApplicationTest.java
git.egatuts.nxtremotecontroller.GlobalUtils.java
git.egatuts.nxtremotecontroller.activity.ActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.BaseActivity.java
git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
git.egatuts.nxtremotecontroller.activity.DefaultActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.MainActivity.java
git.egatuts.nxtremotecontroller.activity.SettingsActivity.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothConstants.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothUtils.java
git.egatuts.nxtremotecontroller.bluetooth.NXTConnector.java
git.egatuts.nxtremotecontroller.device.PairedDeviceAdapter.java
git.egatuts.nxtremotecontroller.device.PairedDeviceItemClickListener.java
git.egatuts.nxtremotecontroller.device.PairedDeviceViewHolder.java
git.egatuts.nxtremotecontroller.device.PairedDevice.java
git.egatuts.nxtremotecontroller.exception.SocketCreationException.java
git.egatuts.nxtremotecontroller.fragment.ActivityBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BluetoothFragment.java
git.egatuts.nxtremotecontroller.fragment.ControllerBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.DefaultFragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.FragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.HomeFragment.java
git.egatuts.nxtremotecontroller.fragment.LocalControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.OnlineControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.ScanFragment.java
git.egatuts.nxtremotecontroller.fragment.SettingsFragment.java
git.egatuts.nxtremotecontroller.listener.AnimationEndListener.java
git.egatuts.nxtremotecontroller.listener.AppKillerListener.java
git.egatuts.nxtremotecontroller.listener.BaseListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothDiscoveryListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothEnableListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothPairingListener.java
git.egatuts.nxtremotecontroller.navigation.DrawerItemViewHolder.java
git.egatuts.nxtremotecontroller.navigation.DrawerItem.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerAdapter.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerCallback.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerFragment.java
git.egatuts.nxtremotecontroller.preference.PreferencesUtils.java
git.egatuts.nxtremotecontroller.receiver.AppKillerReceiver.java
git.egatuts.nxtremotecontroller.receiver.BaseReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothDiscoveryReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothEnableReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothPairingReceiver.java
git.egatuts.nxtremotecontroller.thread.BaseThread.java
git.egatuts.nxtremotecontroller.thread.ConnectThread.java
git.egatuts.nxtremotecontroller.thread.ConnectedThread.java
git.egatuts.nxtremotecontroller.views.BaseIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.BaseProgressDialog.java
git.egatuts.nxtremotecontroller.views.JoystickView.java
git.egatuts.nxtremotecontroller.views.LongIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.ShortIndeterminateProgressDialog.java