Skip to content

Commit

Permalink
Merge pull request #46 from HackForEquality/add-vote-day
Browse files Browse the repository at this point in the history
Add vote day
  • Loading branch information
Ankhwatcher committed May 19, 2015
2 parents 8a7d60d + d66d4a6 commit dd4fefd
Show file tree
Hide file tree
Showing 47 changed files with 400 additions and 156 deletions.
4 changes: 2 additions & 2 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "ie.yesequality.yesequality"
minSdkVersion 15
targetSdkVersion 22
versionCode 4
versionName "1.0.1"
versionCode 5
versionName "1.0.5"
}

Properties props = new Properties()
Expand Down
15 changes: 8 additions & 7 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<application
android:name=".YesEqualityApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -40,7 +41,7 @@


<activity
android:name=".CameraMainActivityTest"
android:name=".CameraActivity"
android:label="@string/title_activity_camera_main"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.Camera">
Expand All @@ -49,32 +50,32 @@
<activity
android:name=".PhotoActivity"
android:label="Share Photo"
android:parentActivityName=".CameraMainActivityTest"
android:parentActivityName=".CameraActivity"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".CameraMainActivityTest"/>
android:value=".CameraActivity" />
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:parentActivityName=".CameraMainActivityTest"
android:parentActivityName=".CameraActivity"
android:screenOrientation="portrait"
android:theme="@style/AppThemeDarkAction">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".CameraMainActivityTest"/>
android:value=".CameraActivity" />
</activity>

<activity
android:name=".NotificationActivity"
android:label="@string/title_activity_notification"
android:parentActivityName=".CameraMainActivityTest"
android:parentActivityName=".CameraActivity"
android:screenOrientation="portrait"
android:theme="@style/AppThemeDarkAction">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".CameraMainActivityTest"/>
android:value=".CameraActivity" />
</activity>

<receiver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,38 @@
import ie.yesequality.yesequality.utils.BitmapUtils;
import ie.yesequality.yesequality.views.CameraOverlayView;

public class CameraMainActivityTest extends AppCompatActivity implements TextureView
public class CameraActivity extends AppCompatActivity implements TextureView
.SurfaceTextureListener,
Camera.PictureCallback {
public static final String TAG = "CameraMainActivity";
private static final int PICTURE_QUALITY = 100;
private static final int[] AllVoteBadges = new int[]{R.drawable.ic_wm_i_voted,
R.drawable.ic_wm_i_voted_color,
R.drawable.ic_wm_its_yes,
R.drawable.ic_wm_its_yes_color,
R.drawable.ic_wm_thank_you,
R.drawable.ic_wm_thank_you_color,
R.drawable.ic_wm_vote_for_me,
R.drawable.ic_wm_vote_for_me_color,
R.drawable.ic_wm_yes_im_voting,
R.drawable.ic_wm_yes_im_voting_color,
R.drawable.ic_wm_we_voting,
R.drawable.ic_wm_we_voting_color,
R.drawable.ic_wm_ta,
R.drawable.ic_wm_ta_color,
R.drawable.ic_wm_yes,
R.drawable.ic_wm_yes_color
};
private static int[] sVoteBadges = new int[]{R.drawable.ic_wm_vote_for_me,
R.drawable.ic_wm_vote_for_me_color,
R.drawable.ic_wm_yes_im_voting,
R.drawable.ic_wm_yes_im_voting_color,
R.drawable.ic_wm_we_voting,
R.drawable.ic_wm_we_voting_color,
R.drawable.ic_wm_ta,
R.drawable.ic_wm_ta_color,
R.drawable.ic_wm_yes,
R.drawable.ic_wm_yes_color
};
@InjectView(R.id.tbActionBar)
protected Toolbar tbActionBar;
@InjectView(R.id.rlSurfaceLayout)
Expand All @@ -63,26 +90,10 @@ public class CameraMainActivityTest extends AppCompatActivity implements Texture
protected ImageView selfieButton;
@InjectView(R.id.camera_overlay)
protected CameraOverlayView cameraOverlayView;

TextureView mTextureView;
private Camera mCamera;

private Camera.Size optimalSize;
private int mCameraId;


private int[] mVoteBadges = new int[]{R.drawable.ic_wm_vote_for_me,
R.drawable.ic_wm_vote_for_me_color,
R.drawable.ic_wm_yes_im_voting,
R.drawable.ic_wm_yes_im_voting_color,
R.drawable.ic_wm_we_voting,
R.drawable.ic_wm_we_voting_color,
R.drawable.ic_wm_ta,
R.drawable.ic_wm_ta_color,
R.drawable.ic_wm_yes,
R.drawable.ic_wm_yes_color
};

private int mSelectedBadge = 0;
private float mPreviewScale;

Expand Down Expand Up @@ -143,18 +154,22 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.surface_camera_layout_test);
ButterKnife.inject(this);

if (((YesEqualityApplication) getApplication()).isVotingStarted()) {
sVoteBadges = AllVoteBadges;
}

tbActionBar.setTitle(R.string.app_name);
tbActionBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_info:
Intent infoIntent = new Intent(CameraMainActivityTest.this, MainActivity
Intent infoIntent = new Intent(CameraActivity.this, MainActivity
.class);
startActivity(infoIntent);
return true;
case R.id.action_reminders:
Intent reminderIntent = new Intent(CameraMainActivityTest.this,
Intent reminderIntent = new Intent(CameraActivity.this,
NotificationActivity.class);
startActivity(reminderIntent);
return true;
Expand Down Expand Up @@ -203,19 +218,19 @@ public boolean onTouch(View v, MotionEvent event) {
});


ivWaterMarkPic.setImageResource(mVoteBadges[mSelectedBadge]);
ivWaterMarkPic.setImageResource(sVoteBadges[mSelectedBadge]);
ivWaterMarkPic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getSharedPreferences(Constants.PREFS_NAME, MODE_PRIVATE).edit().putBoolean
(Constants.WATERMARK_CLICKED, true).apply();
if (mSelectedBadge >= mVoteBadges.length - 1) {
if (mSelectedBadge >= sVoteBadges.length - 1) {
mSelectedBadge = 0;
} else {
mSelectedBadge++;
}

ivWaterMarkPic.setImageResource(mVoteBadges[mSelectedBadge]);
ivWaterMarkPic.setImageResource(sVoteBadges[mSelectedBadge]);
ivWaterMarkPic.setVisibility(View.VISIBLE);
ivWaterMarkPic.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
Expand Down Expand Up @@ -338,7 +353,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
mCamera.startPreview();

} catch (Exception e) {
Log.d(TAG, "Error starting mCamera preview: " + e.getMessage());
Log.d(this.getClass().getSimpleName(), "Error starting mCamera preview: " + e.getMessage());
}
}

Expand Down Expand Up @@ -415,18 +430,14 @@ void moveWaterMarkWithinBounds() {
ivWaterMarkPic.setX(0);
} else if (rlSurfaceLayout.getWidth() - internalX < ivWaterMarkPic.getWidth() / 2) {
ivWaterMarkPic.setX(rlSurfaceLayout.getWidth() - ivWaterMarkPic.getWidth());
} /*else {
ivWaterMarkPic.setX(internalX - (ivWaterMarkPic.getWidth() / 2));
}*/
}


if (internalY < ivWaterMarkPic.getHeight() / 2) {
ivWaterMarkPic.setY(0);
} else if (rlSurfaceLayout.getHeight() - internalY < ivWaterMarkPic.getHeight() / 2) {
ivWaterMarkPic.setY(rlSurfaceLayout.getHeight() - ivWaterMarkPic.getHeight());
} /*else {
ivWaterMarkPic.setY(internalY - (ivWaterMarkPic.getHeight() / 2));
}*/
}
}


Expand Down Expand Up @@ -483,7 +494,7 @@ public void saveAndSharePicture(Bitmap bitmap) {
} catch (IOException exception) {
showSavingPictureErrorToast();

Log.w(TAG, "IOException during saving bitmap", exception);
Log.w(this.getClass().getSimpleName(), "IOException during saving bitmap", exception);
return;
}

Expand Down Expand Up @@ -555,6 +566,10 @@ public void onPictureTaken(byte[] data, Camera camera) {
}


if (sVoteBadges[mSelectedBadge] == R.drawable.ic_wm_i_voted || sVoteBadges[mSelectedBadge] == R.drawable.ic_wm_i_voted_color) {
getSharedPreferences(Constants.PREFS_NAME, MODE_PRIVATE).edit().putBoolean(Constants.HAS_VOTED, true).apply();
}

Bitmap waterMark = ((BitmapDrawable) ivWaterMarkPic.getDrawable()).getBitmap();

bitmap = BitmapUtils.cropBitmapToSquare(bitmap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
public interface Constants {
String PREFS_NAME = "ie.yesequality.preferences";
String WATERMARK_CLICKED = "watermark clicked";
String HAS_VOTED = "has voted";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package ie.yesequality.yesequality;


import android.database.DataSetObserver;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class ContributorsFragment extends ListFragment {

private static final String ARG_ABOVE_TEXT = "ABOVE_TEXT";
private static final String ARG_COLOR_ID = "COLOR_ID";
private static final String ARG_TEXT_COLOR_ID = "TEXT_COLOR_ID";
private static final String ARG_CONTRIBUTORS = "CONTRIBUTORS";
@InjectView(R.id.information_above_text)
protected TextView information_above_text;
@InjectView(android.R.id.list)
protected ListView list;
private int aboveTextId;
private String[] mContributors;
private int textColor;
private int colorId;

/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public ContributorsFragment() {
}

public static ContributorsFragment newInstance(int aboveTextID, int colorID, int textColorID, int contributors) {
ContributorsFragment fragment = new ContributorsFragment();
Bundle args = new Bundle();
args.putInt(ARG_ABOVE_TEXT, aboveTextID);
args.putInt(ARG_COLOR_ID, colorID);
args.putInt(ARG_TEXT_COLOR_ID, textColorID);
args.putInt(ARG_CONTRIBUTORS, contributors);
fragment.setArguments(args);

return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getArguments() != null) {
aboveTextId = getArguments().getInt(ARG_ABOVE_TEXT);
colorId = getArguments().getInt(ARG_COLOR_ID);
textColor = getResources().getColor(getArguments().getInt(ARG_TEXT_COLOR_ID));
mContributors = getResources().getStringArray(getArguments().getInt(ARG_CONTRIBUTORS));
}


}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_contributors, container, false);
rootView.setBackgroundResource(colorId);
ButterKnife.inject(this, rootView);

information_above_text.setText(aboveTextId);
information_above_text.setTextColor(textColor);

list.setAdapter(new ListAdapter() {
@Override
public boolean areAllItemsEnabled() {
return false;
}

@Override
public boolean isEnabled(int position) {
return false;
}

@Override
public void registerDataSetObserver(DataSetObserver observer) {

}

@Override
public void unregisterDataSetObserver(DataSetObserver observer) {

}

@Override
public int getCount() {
return mContributors.length;
}

@Override
public String getItem(int position) {
return mContributors[position];
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public boolean hasStableIds() {
return true;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) convertView;
if (textView == null) {
textView = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.simple_list_item, parent, false);
textView.setTextColor(textColor);
}
textView.setText(getItem(position));

return textView;
}

@Override
public int getItemViewType(int position) {
return 0;
}

@Override
public int getViewTypeCount() {
return 1;
}

@Override
public boolean isEmpty() {
return mContributors.length != 0;
}
});
return rootView;
}


}
Loading

0 comments on commit dd4fefd

Please sign in to comment.