編輯:關於Android編程
public class CameraRequestManager extends RequestManager { // Singleton management private static CameraRequestManager sInstance; public synchronized static CameraRequestManager from(Context context) { if (sInstance == null) { sInstance = new CameraRequestManager(context); } return sInstance; } private CameraRequestManager(Context context) { super(context,CameraRequestService.class); } }2.創建一個請求工廠,來創建各種不同的請求,這裡就提供了一個返回打開攝像頭的請求.
public final class CameraRequestFactory { // Request types public static final int REQUEST_TYPE_OPEN_CAMERA = 0; // Response data public static final String BUNDLE_EXTRA_SWITCH = "cn.jesse.camera.datadroid.data.switch"; public static final String BUNDLE_EXTRA_OPEN_CAMERA = "cn.jesse.camera.datadroid.data.opencamera"; public static final String BUNDLE_EXTRA_RESULT = "com.foxykeep.datadroidpoc.extra.result"; public static final String BUNDLE_EXTRA_ERROR_MESSAGE = "com.foxykeep.datadroidpoc.extra.errorMessage"; public static Request getOpeningCameraOperation(int type){ Request request = new Request(REQUEST_TYPE_OPEN_CAMERA); request.setMemoryCacheEnabled(true); request.put(OpenCameraOperation.PARAM_METHOD, type); return request; } }
public class OpenCameraOperation implements Operation { private final String TAG = OpenCameraOperation.class.getSimpleName(); public static final String PARAM_METHOD = "cn.jesse.camera.extra.cameraType"; @Override public Bundle execute(Context context, Request request) throws ConnectionException, DataException, CustomRequestException { Log.i(TAG, "execute"); int cameraType = request.getInt(PARAM_METHOD); Log.i(TAG, "execute, camera type" + cameraType); Bundle bundle = new Bundle(); bundle.putInt(CameraRequestFactory.BUNDLE_EXTRA_SWITCH, CameraRequestFactory.REQUEST_TYPE_OPEN_CAMERA); bundle.putBoolean(CameraRequestFactory.BUNDLE_EXTRA_OPEN_CAMERA,true); return bundle; } }
public class CameraRequestService extends RequestService { @Override public Operation getOperationForType(int requestType) { switch (requestType) { case CameraRequestFactory.REQUEST_TYPE_OPEN_CAMERA: return new OpenCameraOperation(); } return null; } @Override protected Bundle onCustomRequestException(Request request, CustomRequestException exception) { if (exception instanceof MyCustomRequestException) { Bundle bundle = new Bundle(); bundle.putString(CameraRequestFactory.BUNDLE_EXTRA_ERROR_MESSAGE, "MyCustomRequestException thrown."); return bundle; } return super.onCustomRequestException(request, exception); } }
public abstract class DataDroidActivity extends FragmentActivity { private static final String SAVED_STATE_REQUEST_LIST = "savedStateRequestList"; protected CameraRequestManager mRequestManager; protected ArrayListmRequestList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mRequestManager = CameraRequestManager.from(this); if (savedInstanceState != null) { mRequestList = savedInstanceState.getParcelableArrayList(SAVED_STATE_REQUEST_LIST); } else { mRequestList = new ArrayList (); } } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelableArrayList(SAVED_STATE_REQUEST_LIST, mRequestList); } protected void showBadDataErrorDialog() { new ErrorDialogFragmentBuilder(this).setTitle(R.string.dialog_error_data_error_title) .setMessage(R.string.dialog_error_data_error_message).show(); } }
public class CameraActivity extends DataDroidActivity implements ActionBar.OnNavigationListener, RequestListener, ConnectionErrorDialogListener{ private String TAG = CameraActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera); Log.i(TAG, "CameraActivity has been created"); Request openCameraRequest = CameraRequestFactory.getOpeningCameraOperation(Definition.CameraType.Default); mRequestManager.execute(openCameraRequest, this); mRequestList.add(openCameraRequest); } @Override public void onRequestFinished(Request request, Bundle bundle) { if (mRequestList.contains(request)) { setProgressBarIndeterminateVisibility(false); mRequestList.remove(request); int choose = bundle.getInt(CameraRequestFactory.BUNDLE_EXTRA_SWITCH); switch(choose){ case CameraRequestFactory.REQUEST_TYPE_OPEN_CAMERA:{ boolean openCameraStatus = false; openCameraStatus = bundle.getBoolean(CameraRequestFactory.BUNDLE_EXTRA_OPEN_CAMERA); if(openCameraStatus){ Log.i(TAG, "open camera succeed"); }else{ } break; } } } } }
ListView是一種非常常見的一個組件,以垂直列表的形式顯示列表項。而完成一個簡單的ListView只需要這麼三個步驟:1、在布局文件XML中添加ListView並配置
Android開發:LayoutParams的用法 LayoutParams繼承於Android.View.ViewGroup.LayoutP
項目效果如下:項目目錄結構如下:代碼如下:AudioManager.javapackage com.xuliugen.weichat;import java.io.Fil
IT行業是一個踩在巨人肩膀上前進的行業,否則做的事情不一定有意義,所以我也是基於havlenapetr移植的ffmpeg基礎上做了些改進,他做的主要貢獻有:1. 移植了f