[Android General] sir_mosio:
hi everyone

i'm very noob in android because i'm a Java EE developer.

ok i have one apk file that i want to change the source code in to JAVA.

i decompiled the apk file in two ways:

first, i used apktool ,dex2jar, jd-ui and then i got this java code :

package com.sunglab.bigbanghd;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.*;
//import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageButton;

public class MainActivity
extends Activity
implements SensorEventListener
{
public static final int Amazon = 1;
public static final int Google = 0;
public static boolean IsthatPlaying = true;
public static final int Samsung = 3;
public static final int Tstore = 2;
public static MediaPlayer mPlayer;
public static int store = WallpaperSettings.store;
public int MusicNumber = 0;
Handler handler;
Intent intent;
GL2JNIView.Renderer mRenderer;
private GL2JNIView mView;
Sensor m_ot_sensor;
SensorManager m_sensor_manager;
ImageButton menu_Button;

public void abc(int paramInt)
{
switch (paramInt)
{
}
do
{
do
{
do
{
do
{
do
{
return;
Log.e("else", "Playing 0");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034112);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 1");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034113);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 2");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034114);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 3");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034115);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 4");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034116);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
}

public void onAccuracyChanged(Sensor paramSensor, int paramInt)
{
Log.e("Sensor working", "Good ratated2s");
}

public void onBackPressed()
{
Log.e("omg", "Back key");
AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
localBuilder.setIcon(2130837507);
if ((store == 2) || (store == 3)) {
localBuilder.setTitle("이 앱을 종료 하시겠습니까?");
}
for (;;)
{
localBuilder.setCancelable(false);
if ((store != 2) && (store != 3)) {
localBuilder.setPositiveButton("More Apps", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
switch (MainActivity.store)
{
}
for (;;)
{
MainActivity.this.startActivity(MainActivity.this.intent);
return;
MainActivity.this.intent = new Intent("android.intent.action.VIEW", Uri.parse("xxxx"));
continue;
MainActivity.this.intent = new Intent("android.intent.action.VIEW", Uri.parse("xxx"));
}
}
});
}
localBuilder.setNeutralButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
paramAnonymousDialogInterface.cancel();
}
});
localBuilder.setNegativeButton("Exit", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
MainActivity.this.finish();
}
});
localBuilder.show();
return;
localBuilder.setTitle("Do you need More SungLab Apps ?");
}
}

public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
Log.e("gg", "onCreate");
this.m_sensor_manager = ((SensorManager)getSystemService("sensor"));
this.m_ot_sensor = this.m_sensor_manager.getDefaultSensor(3);
this.mView = new GL2JNIView(getApplication());
setContentView(this.mView);
SharedPreferences localSharedPreferences = getSharedPreferences("wallpaperSet", 0);
int i = localSharedPreferences.getInt("THICK", 5);
int j = localSharedPreferences.getInt("TAIL", 7);
int k = localSharedPreferences.getInt("NUMBER", 5999);
int m = localSharedPreferences.getInt("COLORS", 0);
if (Boolean.valueOf(localSharedPreferences.getBoolean("MUSIC", true)).booleanValue()) {}
for (IsthatPlaying = true;; IsthatPlaying = false)
{
GL2JNIView.Renderer.number = k + 1;
GL2JNIView.Renderer.tail = 0.99F - (0.2F - 0.02F * j);
GL2JNIView.Renderer.thick = 1.0F + 0.4F * i;
GL2JNIView.Renderer.colors = m;
addContentView(((LayoutInflater)getSystemService("layout_inflater")).inflate(2130903040, null), new ViewGroup.LayoutParams(-1, -1));
getWindow().setFlags(128, 128);
mPlayer = MediaPlayer.create(this, 2131034112);
if (!IsthatPlaying) {
mPlayer.pause();
}
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
this.menu_Button = ((ImageButton)findViewById(2131296256));
this.menu_Button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
MainActivity.this.startActivity(new Intent(MainActivity.this, WallpaperSettings.class));
}
});
return;
}
}

protected void onDestroy()
{
super.onDestroy();
this.mView = null;
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.release();
mPlayer = null;
Log.e("omg", "Destroy");
}

public void onHomePressed()
{
Log.e("omg", "Home key");
}

protected void onPause()
{
super.onPause();
this.mView.onPause();
if (IsthatPlaying) {
mPlayer.pause();
}
this.m_sensor_manager.unregisterListener(this);
Log.e("omg", "onPause");
}

protected void onResume()
{
super.onResume();
this.mView.onResume();
Log.e("omg", "onResume");
if (Boolean.valueOf(getSharedPreferences("wallpaperSet", 0).getBoolean("MUSIC", true)).booleanValue())
{
IsthatPlaying = true;
if (!IsthatPlaying) {
break label82;
}
mPlayer.start();
}
for (;;)
{
this.m_sensor_manager.registerListener(this, this.m_ot_sensor, 2);
return;
IsthatPlaying = false;
break;
label82:
mPlayer.pause();
}
}

public void onSensorChanged(SensorEvent paramSensorEvent)
{
if (paramSensorEvent.sensor.getType() == 3)
{
if ((int)paramSensorEvent.values[2] > 45) {
GL2JNIView.Renderer.DefinallyROTATION = -90;
}
}
else {
return;
}
if ((int)paramSensorEvent.values[2] < -45)
{
GL2JNIView.Renderer.DefinallyROTATION = 90;
return;
}
GL2JNIView.Renderer.DefinallyROTATION = 0;
}

public boolean onTouchEvent(MotionEvent paramMotionEvent)
{
int i = paramMotionEvent.getPointerCount();
int j = 0;
if (j >= i) {
switch (paramMotionEvent.getAction())
{
}
}
for (;;)
{
return true;
GL2JNIView.TouchMoveNumber(paramMotionEvent.getX(j), paramMotionEvent.getY(j), j, paramMotionEvent.getPointerCount());
j++;
break;
GL2JNIView.TouchUpNumber();
continue;
GL2JNIView.TouchDownNumber();
continue;
GL2JNIView.TouchDownNumber();
}
}
}

/* Location: C:\jd-gui-windows-1.4.0\classes_dex2jar.jar!\com\sunglab\bigbanghd\MainActivity.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/

and the second way i used backSmali tool and jd-ui , i got this JAVA code:

/**
* Generated by smali2java 1.0.0.558
* Copyright (C) 2013 Hensence.com
*/

package com.sunglab.bigbanghd;

import android.app.Activity;
import android.hardware.SensorEventListener;
import android.media.MediaPlayer;
import android.os.Handler;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.widget.ImageButton;
import android.util.Log;
import android.content.Context;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Application;
import android.view.View;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.Window;
import android.hardware.SensorEvent;
import android.view.MotionEvent;

public class MainActivity extends Activity implements SensorEventListener {
public static final int Amazon = 0x1;
public static final int Google = 0x0;
public int MusicNumber;
public static final int Samsung = 0x3;
public static final int Tstore = 0x2;
Handler handler;
Intent intent;
public static MediaPlayer mPlayer;
GL2JNIView.Renderer mRenderer;
private GL2JNIView mView;
Sensor m_ot_sensor;
SensorManager m_sensor_manager;
ImageButton menu_Button;
public static int store = WallpaperSettings.store;
public static boolean IsthatPlaying = 0x1;

public void onCreate(Bundle p1) {
super.onCreate(p1);
Log.e("gg", "onCreate");
m_sensor_manager = (SensorManager)getSystemService("sensor");
m_ot_sensor = m_sensor_manager.getDefaultSensor(0x3);
mView = new GL2JNIView(getApplication());
setContentView(mView);
SharedPreferences "preferences" = getSharedPreferences("wallpaperSet", 0x0);
int "thickness" = "preferences".getInt("THICK", 0x5);
int "tails" = "preferences".getInt("TAIL", 0x7);
int "particleNumber" = "preferences".getInt("NUMBER", 0x176f);
int "colors" = "preferences".getInt("COLORS", 0x0);
Boolean "music" = Boolean.valueOf("preferences".getBoolean("MUSIC", true));
if("music".booleanValue()) {
IsthatPlaying = 0x1;
} else {
IsthatPlaying = 0x0;
}
GL2JNIView.Renderer.number = ("particleNumber" + 0x1);
GL2JNIView.Renderer.tail = (0x3f7d70a4 # 0.99f - (0x3e4ccccd # 0.2f - ((float)"tails" * 0x3ca3d70a # 0.02f)));
GL2JNIView.Renderer.thick = (0.0f + ((float)"thickness" * 0x3ecccccd # 0.4f));
GL2JNIView.Renderer.colors = "colors";
LayoutInflater "vi" = (LayoutInflater)getSystemService("layout_inflater");
View "v" = "vi".inflate(0x0, 0x0);
addContentView("v", new ViewGroup.LayoutParams(-0x1, -0x1));
getWindow().setFlags(0x80, 0x80);
mPlayer = MediaPlayer.create(this, 0x0);
if(!IsthatPlaying) {
mPlayer.pause();
}
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {

1(MainActivity p1) {
}

public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
menu_Button = (ImageButton)findViewById(0x0);
menu_Button.setOnClickListener(new View.OnClickListener(this) {

2(MainActivity p1) {
}

public void onClick(View p1) {
startActivity(new Intent(this$0, WallpaperSettings.class));
}
});
}

public void abc(int p1) {
switch(p1) {
case 0:
{
Log.e("else", "Playing 0");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x0);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {

3(MainActivity p1) {
}

public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 1:
{
Log.e("else", "Playing 1");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050001);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {

4(MainActivity p1) {
}

public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 2:
{
Log.e("else", "Playing 2");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050002);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {

5(MainActivity p1) {
}

public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 3:
{
Log.e("else", "Playing 3");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050003);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {

6(MainActivity p1) {
}

public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 4:
{
Log.e("else", "Playing 4");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050004);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {

7(MainActivity p1) {
}

public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
break;
}
}
}
}

protected void onPause() {
super.onPause();
mView.onPause();
if(IsthatPlaying) {
mPlayer.pause();
}
m_sensor_manager.unregisterListener(this);
Log.e("omg", "onPause");
}

protected void onResume() {
super.onResume();
mView.onResume();
Log.e("omg", "onResume");
SharedPreferences "preferences" = getSharedPreferences("wallpaperSet", 0x0);
Boolean "music" = Boolean.valueOf("preferences".getBoolean("MUSIC", true));
if("music".booleanValue()) {
IsthatPlaying = 0x1;
} else {
IsthatPlaying = 0x0;
}
if(IsthatPlaying) {
mPlayer.start();
} else {
mPlayer.pause();
}
m_sensor_manager.registerListener(this, m_ot_sensor, 0x2);
}

public void onSensorChanged(SensorEvent p1) {
if(p1.sensor.getType() == 0x3) {
if((int)p1.values[0x2] > 0x2d) {
GL2JNIView.Renderer.DefinallyROTATION = -0x5a;
return;
}
if((int)p1.values[0x2] < -0x2d) {
GL2JNIView.Renderer.DefinallyROTATION = 0x5a;
return;
}
GL2JNIView.Renderer.DefinallyROTATION = 0x0;
}
}

public void onAccuracyChanged(Sensor p1, int p2) {
Log.e("Sensor working", "Good ratated2s");
}

protected void onDestroy() {
super.onDestroy();
mView = 0x0;
if(mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.release();
mPlayer = 0x0;
Log.e("omg", "Destroy");
}

public void onBackPressed() {
Log.e("omg", "Back key");
AlertDialog.Builder "d" = new AlertDialog.Builder(this);
"d".setIcon(0x7f020003);
if((store == 0x2) || (store == 0x3)) {
"d".setTitle("\uc774 \uc571\uc744 \uc885\ub8cc \ud558\uc2dc\uaca0\uc2b5\ub2c8\uae4c?");
} else {
"d".setTitle("Do you need More SungLab Apps ?");
}
"d".setCancelable(false);
if((store != 0x2) && (store != 0x3)) {
"d".setPositiveButton("More Apps", new DialogInterface.OnClickListener(this) {

8(MainActivity p1) {
}

public void onClick(DialogInterface p1, int p2) {
switch(MainActivity.store) {
case 0:
{
new Intent("android.intent.action.VIEW", Uri.parse("xx"));
intent = localIntent1;
break;
}
case 1:
{
new Intent("android.intent.action.VIEW", Uri.parse("xxxx"));
intent = localIntent2;
break;
}
}
startActivity(intent);
}
});
}
"d".setNeutralButton("Cancel", new DialogInterface.OnClickListener(this) {

9(MainActivity p1) {
}

public void onClick(DialogInterface p1, int p2) {
p1.cancel();
}
});
"d".setNegativeButton("Exit", new DialogInterface.OnClickListener(this) {

10(MainActivity p1) {
}

public void onClick(DialogInterface p1, int p2) {
finish();
}
});
"d".show();
}

public void onHomePressed() {
Log.e("omg", "Home key");
}

public boolean onTouchEvent(MotionEvent p1) {
int "pointerCount" = p1.getPointerCount();
for(int "i" = 0x0; "i" >= "pointerCount"; "i" = "i" + 0x1) {
}
GL2JNIView.TouchMoveNumber(p1.getX("i"), p1.getY("i"), "i", p1.getPointerCount());
switch(p1.getAction()) {
case 1:
{
GL2JNIView.TouchUpNumber();
break;
}
case 0:
{
GL2JNIView.TouchDownNumber();
break;
}
case 5:
{
GL2JNIView.TouchDownNumber();
break;
}
case 2:
case 3:
case 4:
{
return true;
}
}
}
}

now i have a question why both of java codes are not the same?? for example, in the first one, we have some (do while) loops but in the second way we don't have them???

and as you can see, in the first one some lines seem wrong (in abc() method or it has written for( ;; ) ).

And also in the second one, in abc() method, we have switch case but in the first one we don't have it.

i want to edit some lines and codes but it seems the original decompiled code doesn't work.