android camer 图片回显界面照片分享到微博、人人、彩信、蓝牙的功能实现

当然,分享到人人需要安装人人客户端,其他也是一样。代码如下:

BackDisplay.java

/**
 * Add by Liuzw for pic back display
 */
package com.android.camera.ui;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.android.camera.R;
import com.android.camera.Thumbnail;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;


public class BackDisplay extends Activity implements View.OnClickListener, OnItemClickListener{

	private static final String TAG = "lxy";
    private boolean menuLayoutShowing;
    private boolean rowsShowing;
    private Button btnShare;
    private Button btnEdit;
    private Button btnDelete;
    private ImageView mImageView;
    private Thumbnail mThumbnail;
    private LinearLayout functionButtons;
    private ListView mShareList;
    private String mMimeType;
    private static final String ADAPTER_COLUMN_ICON = "icon";
    private ArrayList<ComponentName> mComponent = new ArrayList<ComponentName>();

	
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.back_display);
		initUI();
	}

	private void initUI(){
		// Load the thumbnail from the disk.
        mThumbnail = Thumbnail.loadFrom(new File(getFilesDir(), Thumbnail.LAST_THUMB_FILENAME));
        
		mImageView = (ImageView) findViewById(R.id.photos_pic);
		mImageView.setImageBitmap(mThumbnail.getBitmap());
		//Drawable d = Drawable.createFromPath("/sdcard/DCIM/Camera/IMG_20000101_091249.jpg");
		//mImageView.setImageBitmap(((BitmapDrawable)d).getBitmap());
		mImageView.setOnClickListener(this);

		functionButtons = (LinearLayout) findViewById(R.id.funtion_buttons);
		mShareList = (ListView) findViewById(R.id.shared_items);
    	
    	btnShare = (Button) findViewById(R.id.btn_share);
    	btnEdit = (Button) findViewById(R.id.btn_edit);
    	btnDelete = (Button) findViewById(R.id.btn_delete);
    	btnEdit.setOnClickListener(this);
    	btnShare.setOnClickListener(this);
    	btnDelete.setOnClickListener(this);
    	
    	mMimeType = this.getContentResolver().getType(mThumbnail.getUri());
    	createShareMenu();
    }

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch(arg0.getId()){
		case R.id.photos_pic:
			clickPhotosPic();
            break;
        case R.id.btn_share:
        	clickSharedButton();
        	break;
        case R.id.btn_edit:
			//Toast.makeText(BackDisplay.this, "Edit", Toast.LENGTH_SHORT).show();
	
        	break;
        case R.id.btn_delete:
			Toast.makeText(BackDisplay.this, "Delete", Toast.LENGTH_SHORT).show();
        	break;
    	default:
    		break;
        }
	}
	
	private void clickPhotosPic(){
		if(menuLayoutShowing){
    		if(rowsShowing){
        		rowsShowing = false;
        		mShareList.setVisibility(View.GONE);
        	}
    		menuLayoutShowing = false;
    		functionButtons.setVisibility(View.GONE);
    		
    	} else{
    		menuLayoutShowing = true;
    		functionButtons.setVisibility(View.VISIBLE);
    	}
	}
	
	private void clickSharedButton(){
		if(rowsShowing){
    		rowsShowing = false;
    		mShareList.setVisibility(View.GONE);
    	} else{
    		rowsShowing = true;
    		mShareList.setVisibility(View.VISIBLE);
    	}
	}
	
	private final SimpleAdapter.ViewBinder mViewBinder =
        new SimpleAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(final View view, final Object data,
                    final String text) {
                if (view instanceof ImageView) {
                    ((ImageView) view).setImageDrawable((Drawable) data);
                    return true;
                }
                return false;
            }
        };
	
	public void createShareMenu() {
        PackageManager packageManager = getPackageManager();
        List<ResolveInfo> infos = packageManager.queryIntentActivities(
                new Intent(Intent.ACTION_SEND).setType(mMimeType), 0);

        ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String, Object>>();
        for (ResolveInfo info : infos) {
            ComponentName component = new ComponentName(
                    info.activityInfo.packageName, info.activityInfo.name);
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put(ADAPTER_COLUMN_ICON, info.loadIcon(packageManager));
            items.add(map);
            mComponent.add(component);
        }

        SimpleAdapter listItemAdapter = new SimpleAdapter(this, items,
                R.layout.share_icon,
                new String[] {ADAPTER_COLUMN_ICON},
                new int[] {R.id.icon});

        listItemAdapter.setViewBinder(mViewBinder);
        mShareList.setAdapter(listItemAdapter);
        mShareList.setOnItemClickListener(this);
    }

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
		// TODO Auto-generated method stub
		Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType(mMimeType);
        intent.putExtra(Intent.EXTRA_STREAM, mThumbnail.getUri());
        intent.setComponent(mComponent.get(index));
        startActivity(intent);
	}
}

布局文件 back_display.xml:

<!-- 	Add by Liuzw for show back display interface. -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:camera="http://schemas.android.com/apk/res/com.android.camera"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom" >

    <ImageView
        android:id="@+id/photos_pic"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center" />
    
    <ListView 
        android:id="@+id/shared_items"
        android:layout_width="130dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="100dip"
        android:visibility="gone"
        android:layout_above="@+id/funtion_buttons"/>

    <LinearLayout 
        android:id="@+id/funtion_buttons"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:orientation="horizontal"
        android:layout_marginLeft="100dip"
        android:layout_marginRight="100dip"
        android:layout_marginBottom="20dip"
        android:background="#88FFFF00"
        android:layout_alignParentBottom="true"
        android:visibility="gone" >
        <Button
	        android:id="@+id/btn_share"
	        style="@style/picBackDisplayButton"
	        android:text="@string/back_display_button_share" />
	    <Button
	        android:id="@+id/btn_edit"
	        style="@style/picBackDisplayButton"
	        android:text="@string/back_display_button_edit" />
	    <Button
	        android:id="@+id/btn_delete"
	        style="@style/picBackDisplayButton"
	        android:text="@string/back_display_button_delete" />
    </LinearLayout>
    

</RelativeLayout>

其中:

<style name="picBackDisplayButton">
        <item name="android:background">#AA836FFF</item>
        <item name="android:textSize">15pt</item>
        <item name="android:layout_height">40dip</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_weight">1</item>
    </style>



布局文件share_icon.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="40dip"
        android:layout_width="fill_parent"
        android:background="#AA836FFF">
    <ImageView android:id="@+id/icon"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"/>
</FrameLayout>

android camer 图片回显界面照片分享到微博、人人、彩信、蓝牙的功能实现_第1张图片




你可能感兴趣的:(android,ListView,layout,delete,button,照片)