Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
naman14 committed May 14, 2016
1 parent 69f9b58 commit 451d57a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 18 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/naman14/arcade/ArcadeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class ArcadeService extends IntentService {

public static final String ACTION_START = "com.naman14.arcade.START";
public static final String ACTION_COMPLETED = "com.naman14.arcade.COMPLETE";
public static final String ACTION_UPDATE_PROGRESS = "com.naman14.arcade.UPDATE_PROGRESS";

public static boolean isRunning;
Expand Down Expand Up @@ -71,7 +72,8 @@ public void onIteration(int currentIteration, int totalIteration) {
arcade.setCompletionListsner(new CompletionListener() {
@Override
public void onComplete() {
arcade.destroyArcade();
Intent localIntent = new Intent(ACTION_COMPLETED);
LocalBroadcastManager.getInstance(ArcadeService.this).sendBroadcast(localIntent);
isRunning = false;
stopSelf();
}
Expand Down
40 changes: 32 additions & 8 deletions app/src/main/java/com/naman14/arcade/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P

Button style, content, start;
RecyclerView styleRecyclerView;
ImageView stylizedImage, styleImagePreview;
View foregroundView, logoView;
ImageView stylizedImage, styleImagePreview, stylingResult;
View foregroundView, logoView, stylingView;
TextView styleButtonText, stylingLog;

private static final int PICK_STYLE_IMAGE = 777;
Expand All @@ -71,7 +71,8 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
private static final int STATE_STYLE_CHOOSE = 2;
private static final int STATE_BEGIN_STYLING = 3;
private static final int STATE_STYLING = 4;
private static final int STATE_EXITING = 5;
private static final int STATE_STYLING_COMPLETED = 5;
private static final int STATE_EXITING = 6;

public boolean downloadingModel = false;

Expand Down Expand Up @@ -99,6 +100,8 @@ protected void onCreate(Bundle savedInstanceState) {
logoView = findViewById(R.id.logoView);
styleButtonText = (TextView) findViewById(R.id.pickStyleText);
stylingLog = (TextView) findViewById(R.id.stylingLog);
stylingResult = (ImageView) findViewById(R.id.stylingResultPreview);
stylingView = findViewById(R.id.stylingView);

styleRecyclerView = (RecyclerView) findViewById(R.id.styles_recyclerview);
styleRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
Expand Down Expand Up @@ -137,6 +140,7 @@ public void onClick(View v) {
animateViewVisiblity(start, false);
animateForegroundView(Color.parseColor("#88000000"), Color.parseColor("#99000000"));
animateViewVisiblity(stylingLog, true);
showLogoView(stylingView);
beginStyling(false);
}
}
Expand All @@ -146,7 +150,8 @@ public void onClick(View v) {

if (ArcadeService.isRunning) {
animateViewVisiblity(content, false);
hideLogoView();
hideLogoView(logoView);
showLogoView(stylingView);
animateViewVisiblity(stylingLog, true);
beginStyling(true);
stylingLog.setText(ArcadeService.currentLog);
Expand Down Expand Up @@ -205,7 +210,7 @@ public void onBackPressed() {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
currentState = STATE_CONTENT_CHOOSE;
content.setVisibility(View.VISIBLE);
showLogoView();
showLogoView(logoView);
hideStyleImages();
moveStyleButton(false);
animateViewVisiblity(content, true);
Expand Down Expand Up @@ -235,6 +240,14 @@ public void onClick(DialogInterface dialog, int which) {
}
}).show();
break;
case STATE_STYLING_COMPLETED:
currentState = STATE_STYLE_CHOOSE;
animateViewVisiblity(styleImagePreview, false);
animateViewVisiblity(start, false);
animateForegroundView(Color.parseColor("#88000000"), Color.parseColor("#44000000"));
showStyleImages();
moveStyleButton(true);
break;
}

}
Expand Down Expand Up @@ -314,7 +327,7 @@ public void run() {
public void run() {
setStylesData();
showStyleImages();
hideLogoView();
hideLogoView(logoView);
animateViewVisiblity(style, true);
moveStyleButton(true);
}
Expand Down Expand Up @@ -374,7 +387,7 @@ private void hideStyleImages() {
.alpha(0.0f);
}

private void hideLogoView() {
private void hideLogoView(View logoView) {
logoView.setVisibility(View.VISIBLE);
logoView.setAlpha(1.0f);
logoView.animate()
Expand All @@ -383,7 +396,7 @@ private void hideLogoView() {
.alpha(0.0f);
}

private void showLogoView() {
private void showLogoView(View logoView) {
logoView.setVisibility(View.VISIBLE);
logoView.setTranslationY(-logoView.getHeight());
logoView.setAlpha(0.0f);
Expand Down Expand Up @@ -573,6 +586,8 @@ private void setupServiceReceiver() {
ResponseReceiver responseReceiver = new ResponseReceiver();
IntentFilter intentFilter = new IntentFilter(ArcadeService.ACTION_UPDATE_PROGRESS);
LocalBroadcastManager.getInstance(this).registerReceiver(responseReceiver, intentFilter);
IntentFilter intentFilter2 = new IntentFilter(ArcadeService.ACTION_COMPLETED);
LocalBroadcastManager.getInstance(this).registerReceiver(responseReceiver, intentFilter2);
}

private class ResponseReceiver extends BroadcastReceiver {
Expand All @@ -592,6 +607,15 @@ public void onReceive(Context context, Intent intent) {
stylingLog.setText(log);
}
break;
case ArcadeService.ACTION_COMPLETED:
currentState = STATE_STYLING_COMPLETED;
serviceRunning = false;
hideLogoView(stylingView);
animateViewVisiblity(stylingResult, true);
String outputPath = Environment.getExternalStorageDirectory() + "/Arcade/outputs.output.png";
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new FadeInBitmapDisplayer(500)).build();
ImageLoader.getInstance().displayImage(Uri.fromFile(new File(outputPath)).toString(), stylingResult, options);
break;
}
}
}
Expand Down
29 changes: 25 additions & 4 deletions app/src/main/res/layout/layout_styling.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,42 @@
android:layout_centerInParent="true" />

<LinearLayout
android:layout_width="match_parent"
android:id="@+id/stylingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical">
android:layout_marginTop="65dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="styling..."
android:textColor="@android:color/white"
android:textSize="40sp" />

<TextView
android:id="@+id/stylingLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:textColor="@android:color/white" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="vertical">

<FrameLayout
android:id="@+id/log_container"
Expand Down
2 changes: 1 addition & 1 deletion arcade/src/main/assets/neural_style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function stylize(params)
end
updateProgress("Saving image")
image.save(filename, disp)
updateProgress("Image saved in %s ", filename)
updateProgress(string.format("Image saved in %s ", filename))
-- onImageSaved(filename, isFinal)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void onImageSaved(String path, boolean isFinal) {
}

//Called from C
public static void onCompleted(String empty) {
public static void onCompleted() {
if (completionListener != null) {
completionListener.onComplete();
}
Expand Down
5 changes: 2 additions & 3 deletions arcade/src/main/jni/arcade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ static void onCompleted(lua_State *L) {

jclass clazz = globalEnv->FindClass("com/naman14/arcade/library/Arcade");
jmethodID onCompleted = globalEnv->GetStaticMethodID(clazz, "onCompleted",
"(Ljava/lang/String;Z)V");

globalEnv->CallStaticVoidMethod(clazz, onCompleted, "");
"()V");
globalEnv->CallStaticVoidMethod(clazz, onCompleted);
globalEnv->DeleteLocalRef(clazz);

}
Expand Down

0 comments on commit 451d57a

Please sign in to comment.