Created
March 8, 2017 09:47
-
-
Save kgundula/a54749bca42604c72dc1cdb587796f27 to your computer and use it in GitHub Desktop.
Fab color capture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package za.co.gundula.app.androidcolorpicker; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
import android.graphics.Color; | |
import android.os.Bundle; | |
import android.preference.PreferenceManager; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.v7.app.AppCompatActivity; | |
import android.util.Log; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity { | |
Context context; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
context = getApplicationContext(); | |
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingActionButton); | |
if (fab != null) { | |
fab.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(final View view) { | |
final ColorPicker colorPicker = new ColorPicker(view.getContext()); | |
colorPicker.setDefaultColorButton(Color.parseColor("#f84c44")).setColumns(5).setOnChooseColorListener(new ColorPicker.OnChooseColorListener() { | |
@Override | |
public void onChooseColor(int position, int color) { | |
Log.d("position:",""+position);// This will be fired only when OK button was tapped | |
if (position == 8) { | |
view.setBackgroundColor(Color.BLUE); | |
} | |
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); | |
SharedPreferences.Editor editor = sharedPreferences.edit(); | |
editor.putInt("capture_background_color", color); | |
editor.apply(); | |
} | |
@Override | |
public void onCancel() { | |
} | |
}).addListenerButton("newButton", new ColorPicker.OnButtonListener() { | |
@Override | |
public void onClick(View v, int position, int color) { | |
Log.d("position",""+position); | |
} | |
}).setRoundColorButton(true).show(); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment