Permalink
Browse files

added PublishActivity and SendingProgressView

  • Loading branch information...
frogermcs committed Mar 8, 2015
1 parent 5a6d093 commit 7af4e8c967217c0238957f1d4103cc7ec6155d76
@@ -40,7 +40,14 @@
<activity
android:name=".ui.activity.TakePhotoActivity"
android:screenOrientation="portrait"
- android:theme="@style/AppTheme.TransparentActivity.FullScreen" />
+ android:theme="@style/AppTheme.TransparentActivity" />
+ <activity
+ android:name=".ui.activity.PublishActivity"
+ android:screenOrientation="portrait"
+ android:theme="@style/AppTheme"
+ android:windowSoftInputMode="stateHidden">
+
+ </activity>
</application>
</manifest>
@@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
+import android.os.Build;
import android.view.Display;
import android.view.WindowManager;
@@ -40,4 +41,8 @@ public static int getScreenWidth(Context c) {
return screenWidth;
}
+
+ public static boolean isAndroid5() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
+ }
}
@@ -4,6 +4,7 @@
import android.animation.AnimatorListenerAdapter;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
@@ -22,6 +23,8 @@
public class MainActivity extends BaseActivity implements FeedAdapter.OnFeedItemClickListener,
FeedContextMenu.OnFeedContextMenuItemClickListener {
+ public static final String ACTION_SHOW_LOADING_ITEM = "action_show_loading_item";
+
private static final int ANIM_DURATION_TOOLBAR = 300;
private static final int ANIM_DURATION_FAB = 400;
@@ -67,6 +70,24 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
});
}
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ if (ACTION_SHOW_LOADING_ITEM.equals(intent.getAction())) {
+ showFeedLoadingItemDelayed();
+ }
+ }
+
+ private void showFeedLoadingItemDelayed() {
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ rvFeed.smoothScrollToPosition(0);
+ feedAdapter.showLoadingView();
+ }
+ }, 500);
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
@@ -0,0 +1,155 @@
+package io.github.froger.instamaterial.ui.activity;
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.ViewTreeObserver;
+import android.view.animation.OvershootInterpolator;
+import android.widget.ImageView;
+import android.widget.ToggleButton;
+
+import com.squareup.picasso.Callback;
+import com.squareup.picasso.Picasso;
+
+import butterknife.InjectView;
+import butterknife.OnCheckedChanged;
+import hugo.weaving.DebugLog;
+import io.github.froger.instamaterial.R;
+import io.github.froger.instamaterial.Utils;
+import timber.log.Timber;
+
+/**
+ * Created by Miroslaw Stanek on 21.02.15.
+ */
+public class PublishActivity extends BaseActivity {
+ public static final String ARG_TAKEN_PHOTO_URI = "arg_taken_photo_uri";
+
+ @InjectView(R.id.tbFollowers)
+ ToggleButton tbFollowers;
+ @InjectView(R.id.tbDirect)
+ ToggleButton tbDirect;
+ @InjectView(R.id.ivPhoto)
+ ImageView ivPhoto;
+
+ private boolean propagatingToggleState = false;
+ private Uri photoUri;
+ private int photoSize;
+
+ public static void openWithPhotoUri(Activity openingActivity, Uri photoUri) {
+ Intent intent = new Intent(openingActivity, PublishActivity.class);
+ intent.putExtra(ARG_TAKEN_PHOTO_URI, photoUri);
+ openingActivity.startActivity(intent);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_publish);
+ toolbar.setNavigationIcon(R.drawable.ic_arrow_back_grey600_24dp);
+ photoSize = getResources().getDimensionPixelSize(R.dimen.publish_photo_thumbnail_size);
+
+ if (savedInstanceState == null) {
+ photoUri = getIntent().getParcelableExtra(ARG_TAKEN_PHOTO_URI);
+ } else {
+ photoUri = savedInstanceState.getParcelable(ARG_TAKEN_PHOTO_URI);
+ }
+ updateStatusBarColor();
+
+ ivPhoto.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
+ @Override
+ public boolean onPreDraw() {
+ ivPhoto.getViewTreeObserver().removeOnPreDrawListener(this);
+ loadThumbnailPhoto();
+ return true;
+ }
+ });
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ private void updateStatusBarColor() {
+ if (Utils.isAndroid5()) {
+ getWindow().setStatusBarColor(0xff888888);
+ }
+ }
+
+ private void loadThumbnailPhoto() {
+ ivPhoto.setScaleX(0);
+ ivPhoto.setScaleY(0);
+ Picasso.with(this)
+ .load(photoUri)
+ .centerCrop()
+ .resize(photoSize, photoSize)
+ .into(ivPhoto, new Callback() {
+ @Override
+ public void onSuccess() {
+ ivPhoto.animate()
+ .scaleX(1.f).scaleY(1.f)
+ .setInterpolator(new OvershootInterpolator())
+ .setDuration(400)
+ .setStartDelay(200)
+ .start();
+ }
+
+ @Override
+ public void onError() {
+ }
+ });
+ }
+
+ @Override
+ protected boolean shouldInstallDrawer() {
+ return false;
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_publish, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.action_publish) {
+ bringMainActivityToTop();
+ return true;
+ } else {
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ private void bringMainActivityToTop() {
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ intent.setAction(MainActivity.ACTION_SHOW_LOADING_ITEM);
+ startActivity(intent);
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putParcelable(ARG_TAKEN_PHOTO_URI, photoUri);
+ }
+
+ @OnCheckedChanged(R.id.tbFollowers)
+ public void onFollowersCheckedChange(boolean checked) {
+ if (!propagatingToggleState) {
+ propagatingToggleState = true;
+ tbDirect.setChecked(!checked);
+ propagatingToggleState = false;
+ }
+ }
+
+ @OnCheckedChanged(R.id.tbDirect)
+ public void onDirectCheckedChange(boolean checked) {
+ if (!propagatingToggleState) {
+ propagatingToggleState = true;
+ tbFollowers.setChecked(!checked);
+ propagatingToggleState = false;
+ }
+ }
+}
@@ -4,17 +4,21 @@
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
+import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.hardware.Camera;
+import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewTreeObserver;
+import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
@@ -28,9 +32,13 @@
import com.commonsware.cwac.camera.PictureTransaction;
import com.commonsware.cwac.camera.SimpleCameraHost;
+import java.io.File;
+
import butterknife.InjectView;
import butterknife.OnClick;
+import hugo.weaving.DebugLog;
import io.github.froger.instamaterial.R;
+import io.github.froger.instamaterial.Utils;
import io.github.froger.instamaterial.ui.adapter.PhotoFiltersAdapter;
import io.github.froger.instamaterial.ui.view.RevealBackgroundView;
@@ -68,6 +76,8 @@
private boolean pendingIntro;
private int currentState;
+ private File photoPath;
+
public static void startCameraFromLocation(int[] startingLocation, Activity startingActivity) {
Intent intent = new Intent(startingActivity, TakePhotoActivity.class);
intent.putExtra(ARG_REVEAL_START_LOCATION, startingLocation);
@@ -78,6 +88,7 @@ public static void startCameraFromLocation(int[] startingLocation, Activity star
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_photo);
+ updateStatusBarColor();
updateState(STATE_TAKE_PHOTO);
setupRevealBackground(savedInstanceState);
setupPhotoFilters();
@@ -94,6 +105,13 @@ public boolean onPreDraw() {
});
}
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ private void updateStatusBarColor() {
+ if (Utils.isAndroid5()) {
+ getWindow().setStatusBarColor(0xff111111);
+ }
+ }
+
private void setupRevealBackground(Bundle savedInstanceState) {
vRevealBackground.setFillPaintColor(0xFF16181a);
vRevealBackground.setOnStateChangeListener(this);
@@ -139,10 +157,15 @@ protected void onPause() {
@OnClick(R.id.btnTakePhoto)
public void onTakePhotoClick() {
btnTakePhoto.setEnabled(false);
- cameraView.takePicture(true, false);
+ cameraView.takePicture(true, true);
animateShutter();
}
+ @OnClick(R.id.btnAccept)
+ public void onAcceptClick() {
+ PublishActivity.openWithPhotoUri(this, Uri.fromFile(photoPath));
+ }
+
private void animateShutter() {
vShutter.setVisibility(View.VISIBLE);
vShutter.setAlpha(0.f);
@@ -223,6 +246,12 @@ public void run() {
}
});
}
+
+ @Override
+ public void saveImage(PictureTransaction xact, byte[] image) {
+ super.saveImage(xact, image);
+ photoPath = getPhotoPath();
+ }
}
private void showTakenPicture(Bitmap bitmap) {
Oops, something went wrong.

0 comments on commit 7af4e8c

Please sign in to comment.