import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;

public static Bitmap getBitmapFromURL(String src) {
HttpURLConnection connection = null;
try {
URL url = new URL(src);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}finally{
if(connection!=null)connection.disconnect();
}

}


Posted by yespia.net piacom

댓글을 달아 주세요




import java.text.SimpleDateFormat;

import java.util.Date;

public String getDateString()
{
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.KOREA);
String str_date = df.format(new Date());

return str_date;
}




Posted by yespia.net piacom

댓글을 달아 주세요


MainActivity.java

public class MainActivity extends Activity {


private BackPressCloseHandler backPressCloseHandler;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

backPressCloseHandler = new BackPressCloseHandler(this);

}


}


@Override
public void onBackPressed() {
backPressCloseHandler.onBackPressed();
}



BackPressCloseHandler.java

import android.app.Activity;
import android.widget.Toast;

public class BackPressCloseHandler {

private long backKeyPressedTime = 0;
private Toast toast;

private Activity activity;

public BackPressCloseHandler(Activity context) {
this.activity = context;
}

public void onBackPressed() {
if (System.currentTimeMillis() > backKeyPressedTime + 2000) {
backKeyPressedTime = System.currentTimeMillis();
showGuide();
return;
}
if (System.currentTimeMillis() <= backKeyPressedTime + 2000) {
activity.finish();
toast.cancel();
}
}

public void showGuide() {
toast = Toast.makeText(activity,
"\'뒤로\'버튼을 한번 더 누르시면 종료됩니다.", Toast.LENGTH_SHORT);
toast.show();
}
}


Posted by yespia.net piacom

댓글을 달아 주세요