-
Notifications
You must be signed in to change notification settings - Fork 22
/
SampleActivity.java
217 lines (196 loc) · 8.02 KB
/
SampleActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.vlk.multimager.example;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.OnColorSelectedListener;
import com.flask.colorpicker.builder.ColorPickerClickListener;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import com.vlk.multimager.activities.BaseActivity;
import com.vlk.multimager.activities.GalleryActivity;
import com.vlk.multimager.activities.MultiCameraActivity;
import com.vlk.multimager.adapters.GalleryImagesAdapter;
import com.vlk.multimager.utils.Constants;
import com.vlk.multimager.utils.Image;
import com.vlk.multimager.utils.Params;
import com.vlk.multimager.utils.Utils;
import java.util.ArrayList;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by vansikrishna on 08/06/2016.
*/
public class SampleActivity extends BaseActivity {
@Bind(R.id.recycler_view)
RecyclerView recyclerView;
@Bind(R.id.parentLayout)
LinearLayout parentLayout;
int selectedColor;
int darkenedColor;
@Bind(R.id.multiCaptureButton)
Button multiCaptureButton;
@Bind(R.id.multiPickerButton)
Button multiPickerButton;
@Bind(R.id.customThemeButton)
Button customThemeButton;
@Bind(R.id.call)
ImageView callImageView;
@Bind(R.id.message)
ImageView messageImageView;
@Bind(R.id.contact_us)
TextView contactUsTextView;
@Bind(R.id.app_name)
TextView appNameTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
ButterKnife.bind(this);
selectedColor = fetchAccentColor();
darkenedColor = Utils.getDarkColor(selectedColor);
Utils.setViewsColorStateList(selectedColor, darkenedColor,
customThemeButton,
multiCaptureButton,
multiPickerButton,
callImageView,
messageImageView,
contactUsTextView,
appNameTextView);
}
private int fetchAccentColor() {
TypedValue typedValue = new TypedValue();
TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorAccent});
int color = a.getColor(0, 0);
a.recycle();
return color;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode != RESULT_OK) {
return;
}
switch (requestCode) {
case Constants.TYPE_MULTI_CAPTURE:
handleResponseIntent(intent);
break;
case Constants.TYPE_MULTI_PICKER:
handleResponseIntent(intent);
break;
}
}
private int getColumnCount() {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
float thumbnailDpWidth = getResources().getDimension(R.dimen.thumbnail_width) / displayMetrics.density;
return (int) (dpWidth / thumbnailDpWidth);
}
private void handleResponseIntent(Intent intent) {
ArrayList<Image> imagesList = intent.getParcelableArrayListExtra(Constants.KEY_BUNDLE_LIST);
recyclerView.setHasFixedSize(true);
StaggeredGridLayoutManager mLayoutManager = new StaggeredGridLayoutManager(getColumnCount(), GridLayoutManager.VERTICAL);
mLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setLayoutManager(mLayoutManager);
GalleryImagesAdapter imageAdapter = new GalleryImagesAdapter(this, imagesList, getColumnCount(), new Params());
recyclerView.setAdapter(imageAdapter);
}
@OnClick({R.id.multiCaptureButton, R.id.multiPickerButton, R.id.customThemeButton, R.id.github})
public void onClick(View view) {
switch (view.getId()) {
case R.id.multiCaptureButton:
if (Utils.hasCameraHardware(this))
initiateMultiCapture();
else
Utils.showLongSnack(parentLayout, "Sorry. Your device does not have a camera.");
break;
case R.id.multiPickerButton:
initiateMultiPicker();
break;
case R.id.customThemeButton:
setCustomTheme();
break;
case R.id.github:
navigateToUrl();
break;
}
}
private void navigateToUrl() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/vansikrishna/Multimager.git")));
}
private void setCustomTheme() {
ColorPickerDialogBuilder
.with(this)
.setTitle("Choose color")
.initialColor(selectedColor)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(new OnColorSelectedListener() {
@Override
public void onColorSelected(int selectedColor) {
}
})
.setPositiveButton("OK", new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
changeColor(selectedColor);
}
})
.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.build()
.show();
}
private void changeColor(int selectedColor) {
this.selectedColor = selectedColor;
this.darkenedColor = Utils.getDarkColor(selectedColor);
Utils.showShortSnack(parentLayout, "New color selected" + Integer.toHexString(selectedColor));
// Utils.setViewsColorStateList(customThemeButton, selectedColor, darkenedColor);
// Utils.setViewsColorStateList(multiCaptureButton, selectedColor, darkenedColor);
// Utils.setViewsColorStateList(multiPickerButton, selectedColor, darkenedColor);
Utils.setViewsColorStateList(selectedColor, darkenedColor,
customThemeButton,
multiCaptureButton,
multiPickerButton,
callImageView,
messageImageView,
contactUsTextView,
appNameTextView);
}
private void initiateMultiCapture() {
Intent intent = new Intent(this, MultiCameraActivity.class);
Params params = new Params();
params.setCaptureLimit(10);
params.setToolbarColor(selectedColor);
params.setActionButtonColor(selectedColor);
params.setButtonTextColor(selectedColor);
intent.putExtra(Constants.KEY_PARAMS, params);
startActivityForResult(intent, Constants.TYPE_MULTI_CAPTURE);
}
private void initiateMultiPicker() {
Intent intent = new Intent(this, GalleryActivity.class);
Params params = new Params();
params.setCaptureLimit(10);
params.setPickerLimit(10);
params.setToolbarColor(selectedColor);
params.setActionButtonColor(selectedColor);
params.setButtonTextColor(selectedColor);
intent.putExtra(Constants.KEY_PARAMS, params);
startActivityForResult(intent, Constants.TYPE_MULTI_PICKER);
}
}