android Bitmap to File
case REQUEST_IMAGE_CAPTURE:
File f = getFilesDir();
Bitmap bit = data.getExtras().getParcelable("data");
ImageView imageView = (ImageView) findViewById(R.id.bit);
imageView.setImageBitmap(bit);
try {
FileOutputStream fileOutputStream = new FileOutputStream(f.getPath() + "/xxx.jpg");
bit.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
break;
2017年6月2日金曜日
2017年5月31日水曜日
android 裁剪图片库图片
android 裁剪图片库图片
package com.kankanla.m0531a;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_IMAGE_SELECT = 1;
private static final int REQUEST_IMAGE_CAPTURE = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setCutimg();
}
protected void setCutimg() {
Intent intent = new Intent();
intent.setAction(intent.ACTION_OPEN_DOCUMENT);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_IMAGE_SELECT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_IMAGE_SELECT:
Intent intent = new Intent("com.android.camera.action.CROP");
Uri uri = data.getData();
intent.setData(uri);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
break;
case REQUEST_IMAGE_CAPTURE:
Bitmap bit = data.getExtras().getParcelable("data");
ImageView imageView = (ImageView) findViewById(R.id.bit);
imageView.setImageBitmap(bit);
break;
}
}
}
}
package com.kankanla.m0531a;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_IMAGE_SELECT = 1;
private static final int REQUEST_IMAGE_CAPTURE = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setCutimg();
}
protected void setCutimg() {
Intent intent = new Intent();
intent.setAction(intent.ACTION_OPEN_DOCUMENT);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_IMAGE_SELECT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_IMAGE_SELECT:
Intent intent = new Intent("com.android.camera.action.CROP");
Uri uri = data.getData();
intent.setData(uri);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
break;
case REQUEST_IMAGE_CAPTURE:
Bitmap bit = data.getExtras().getParcelable("data");
ImageView imageView = (ImageView) findViewById(R.id.bit);
imageView.setImageBitmap(bit);
break;
}
}
}
}
2017年5月9日火曜日
Android 片段的生命周期(其 Activity 运行时)
片段的生命周期(其 Activity 运行时)
第一次启动
....m.out: Item_list--------------onAttach----------------
....m.out: Item_list--------------onCreate----------------
....m.out: Item_list--------------onCreateView----------------
....m.out: Item_list--------------onActivityCreated----------------
....m.out: Item_list--------------onStart----------------
....m.out: Item_list--------------onResume----------------
关闭屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
从新开屏幕
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
反转屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
....nla.m0417b I/System.out: Item_list--------------onDestroyView----------------
....nla.m0417b I/System.out: Item_list--------------onDetach----------------
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
退回到上一Activety
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
....nla.m0417b I/System.out: Item_list--------------onDestroyView----------------
....nla.m0417b I/System.out: Item_list--------------onDestroy----------------
....nla.m0417b I/System.out: Item_list--------------onDetach----------------
从概览屏幕中返回
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreate----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
打开概览屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
打开其他Activety
在概览屏幕中删除
....m.out: Item_list--------------onDestroyView----------------
....m.out: Item_list--------------onDestroy----------------
....m.out: Item_list--------------onDetach----------------
按图标重新启动
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreate----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
https://developer.android.com/guide/components/fragments.html
第一次启动
....m.out: Item_list--------------onAttach----------------
....m.out: Item_list--------------onCreate----------------
....m.out: Item_list--------------onCreateView----------------
....m.out: Item_list--------------onActivityCreated----------------
....m.out: Item_list--------------onStart----------------
....m.out: Item_list--------------onResume----------------
关闭屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
从新开屏幕
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
反转屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
....nla.m0417b I/System.out: Item_list--------------onDestroyView----------------
....nla.m0417b I/System.out: Item_list--------------onDetach----------------
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
退回到上一Activety
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
....nla.m0417b I/System.out: Item_list--------------onDestroyView----------------
....nla.m0417b I/System.out: Item_list--------------onDestroy----------------
....nla.m0417b I/System.out: Item_list--------------onDetach----------------
从概览屏幕中返回
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreate----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
打开概览屏幕
....nla.m0417b I/System.out: Item_list--------------onPause----------------
....nla.m0417b I/System.out: Item_list--------------onStop----------------
打开其他Activety
在概览屏幕中删除
....m.out: Item_list--------------onDestroyView----------------
....m.out: Item_list--------------onDestroy----------------
....m.out: Item_list--------------onDetach----------------
按图标重新启动
....nla.m0417b I/System.out: Item_list--------------onAttach----------------
....nla.m0417b I/System.out: Item_list--------------onCreate----------------
....nla.m0417b I/System.out: Item_list--------------onCreateView----------------
....nla.m0417b I/System.out: Item_list--------------onActivityCreated----------------
....nla.m0417b I/System.out: Item_list--------------onStart----------------
....nla.m0417b I/System.out: Item_list--------------onResume----------------
2017年4月24日月曜日
Java interface Callback 2
Java interface Callback 2
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception{
T1 t = new T1();
try{
Thread.sleep(1000);
}catch(Exception e){
}
t.st();
}
}
class T1 implements onTest{
public Oset o;
public T1(){
o = new Oset();
o.setont(this);
}
public void st(){
o.methods();
}
public void getx(){
System.out.println("--------implements onTest--------");
}
}
interface onTest{
public void getx();
}
class Oset {
private onTest ont;
public void setont(onTest ont){
this.ont = ont;
}
public void methods(){
System.out.println("--------------methods------------------");
ont.getx();
}
}
Demo
https://paiza.io/projects/l2lBiluXHzRmjoKsj-cLBA
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception{
T1 t = new T1();
try{
Thread.sleep(1000);
}catch(Exception e){
}
t.st();
}
}
class T1 implements onTest{
public Oset o;
public T1(){
o = new Oset();
o.setont(this);
}
public void st(){
o.methods();
}
public void getx(){
System.out.println("--------implements onTest--------");
}
}
interface onTest{
public void getx();
}
class Oset {
private onTest ont;
public void setont(onTest ont){
this.ont = ont;
}
public void methods(){
System.out.println("--------------methods------------------");
ont.getx();
}
}
Demo
https://paiza.io/projects/l2lBiluXHzRmjoKsj-cLBA
Java interface Callback
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
Oset oset = new Oset();
oset.setont(new onTest(){
public void getx(){
System.out.println("----------------interface Callback---------------");
}
});
try{
Thread.sleep(1000);
}catch(Exception e){
}
oset.methods();
}
}
interface onTest{
public void getx();
}
class Oset {
private onTest ont;
public void setont(onTest ont){
this.ont = ont;
}
public void methods(){
System.out.println("--------------methods------------------");
ont.getx();
}
}
Demo
https://paiza.io/projects/uWqAgbv37VXi3LEWkS4WlQ
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
Oset oset = new Oset();
oset.setont(new onTest(){
public void getx(){
System.out.println("----------------interface Callback---------------");
}
});
try{
Thread.sleep(1000);
}catch(Exception e){
}
oset.methods();
}
}
interface onTest{
public void getx();
}
class Oset {
private onTest ont;
public void setont(onTest ont){
this.ont = ont;
}
public void methods(){
System.out.println("--------------methods------------------");
ont.getx();
}
}
Demo
https://paiza.io/projects/uWqAgbv37VXi3LEWkS4WlQ
2017年4月23日日曜日
Thread.activeCount()
Thread.activeCount()
返回当前线程的线程组中活动线程的数目。
public class T2 {
public static void main(String[] args) {
new Thread(new Runnable() {
public void run() {
while (true) {
// System.out.println(1);
}
}
}).start();
new Thread(new Runnable() {
public void run() {
while (true) {
// System.out.println(2);
}
}
}).start();
new Thread(new Runnable() {
public void run() {
while (true) {
// System.out.println(3);
}
}
}).start();
System.out.println(Thread.activeCount());
}
}
2017年4月11日火曜日
Java ArrayList to String[]
Java ArrayList to String[]
https://paiza.io/projects/3F_iZEjxHh9AUNgPwAohxA
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws Exception {
ArrayList<String> sl = new ArrayList<String>();
sl.add("a");
sl.add("b");
sl.add("c");
String[] temp = sl.toArray(new String[]{});
System.out.println(temp.length);
for( String x:temp){
System.out.println(x);
}
}
}
https://paiza.io/projects/3F_iZEjxHh9AUNgPwAohxA
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws Exception {
ArrayList<String> sl = new ArrayList<String>();
sl.add("a");
sl.add("b");
sl.add("c");
String[] temp = sl.toArray(new String[]{});
System.out.println(temp.length);
for( String x:temp){
System.out.println(x);
}
}
}
登録:
投稿 (Atom)