1.
好开心,自定义相机的对焦框出来了,虽然感觉有点蛋筒。之前也想用画图画的 ,可是因为蛋筒的数据传递问题抛弃了自定义SurfaceView,在Acivity中不能override onDraw方法,暂时不知道可行性。
所以采取的方式是,在相机预览的界面的点击位置显示一个对焦框的图片。这个图片位置的设定,没有直接的通过中心点坐标设置的方法,只能绕道,获得触摸点坐标后,设置图片的Margin。
ViewGroup.MarginLayoutParams 中有setMargins(int left, int top, int right, int bottom)方法
可以设置控件在界面上的上下左右margin。
我要动态显示的ImageView在一个LinearLayout中的FrameLayout中,所以给ImageView设置Parameters的时候用到
FrameLayout.LayoutParams
关键的代码
/** * @描述 自动对焦 * */ AutoFocusCallback autoFocus = new AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) { if (success) { ViewGroup.MarginLayoutParams margin = new ViewGroup.MarginLayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); margin.setMargins((int)(x-46.5), (int)(y-46.5), 0, 0); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( margin); focus.setLayoutParams(params); System.out.println(focus.getLayoutParams().getClass()); focus.setVisibility(ImageView.VISIBLE); /* * 2秒后,自动对焦框消失 * */ Handler timeHandler = new Handler(); timeHandler.post(new Runnable() { @Override public void run() { try { Thread.sleep(2000); if (0 == focus.getVisibility()) { focus.setVisibility(ImageView.GONE); } } catch (InterruptedException e) { e.printStackTrace(); } } }); } } };
2. 拍完照后,在当前界面有一个ScrollView对已经拍摄的照片的缩略图的展示,怎样让那个ScrollView每次滚动到当前拍摄的界面呢。当然用到ScrollView的smoothScrollTo(int x, int y)方法,把它放到一个Runnable中去执行。
每个ImageView都有自己的高度,记录ImageView的个数,x=0,y=ImageView的高度×ImageView的个数。
感谢eoe某用户
关键代码
Handler smoothHandler = new Handler(); smoothHandler.post(new Runnable() { @Override public void run() { int offset = iv.getMeasuredHeight() * photoPromts.length; if (offset < 0) { offset = 0; } scrollView.smoothScrollTo(0, offset); } });
3.在ScrollView中有一个LinearLayout,在这个LinearLayout中才是多个ImageView,怎样给这些ImageView设置监听,能够在点击他们时可以预览大图呢。直接给它setOnclickListener就可以了,只不过我这里的ImageView是final类型,会报
The final local variable iv cannot be assigned, since it is defined in an enclosing type 编译错。
就再定义一个ImageView去代表它
content://sms/inbox 收件箱 content://sms/sent 已发送 content://sms/draft 草稿 content://sms/outbox 发件箱 content://sms/failed 发送失败 content://sms/queued 待发送列表
Location android.permission.ACCESS_COARSE_LOCATION TelephonyManager.getCellLocation GsmCellLocation.getCid GsmCellLocation.getLac GsmCellLocation.getPsc CdmaCellLocation.getBaseStationLatitude CdmaCellLocation.getBaseStationLongitude android.permission.ACCESS_FINE_LOCATION LocationManager.requestLocationUpdates() LocationManager.getLastKnownLocation() Location.getLatitude() Location.getLongitude() android.permission.ACCESS_LOCATION_EXTRA_COMMANDS Bookmarks com.android.browser.permission.READ_HISTORY_BOOKMARKS Browser.BOOKMARKS_URI Browser.SEARCHES_URI content://browser/bookmarks content://browser/searches Browser.getAllBookmarks() Browser.getAllVisitedUrls() Browser.getVisitedHistory() Browser.getVisitedHistoryByOrder Contacts android.permission.READ_CONTACTS Contacts.CONTENT_URI Contacts$People content://contacts ContactsContract.AUTHORITY_URI content://com.android.contacts CallLog.CONTENT_URI CallLog.Calls.CONTENT_URI content://call_log/calls android.permission.WRITE_CONTACTS Contacts.CONTENT_URI Contacts$People content://contacts ContactsContract.AUTHORITY_URI content://com.android.contacts Calendar android.permission.WRITE_CALENDAR Calendar.CONTENT_URI content://com.android.calendar android.permission.READ_CALENDAR Calendar.CONTENT_URI content://com.android.calendar Phone android.permission.CALL_PHONE Intent.ACTION_CALL android.intent.action.CALL android.permission.PROCESS_OUTGOING_CALLS android.intent.action.NEW_OUTGOING_CALL EXTRA_INCOMING_NUMBER android.permission.READ_PHONE_STATE android.intent.action.PHONE_STATE EXTRA_INCOMING_NUMBER EXTRA_STATE TelephonyManager.getLine1Number() TelephonyManager.listen() SMS android.permission.READ_SMS content://sms/ content://mms/ content://mms-sms/ android.permission.RECEIVE_SMS android.permission.SEND_SMS SmsManager.sendTextMessage SmsManager.sendMultipartTextMessage SmsManager.sendDataMessage android.permission.WRITE_SMS content://sms/ content://mms/ content://mms-sms/ android.permission.RECEIVE_MMS android.permission.RECEIVE_WAP_PUSH Dangerous OPS android.permission.MOUNT_FORMAT_FILESYSTEMS IMountService.formatVolume() android.permission.MOUNT_UNMOUNT_FILESYSTEMS android.permission.KILL_BACKGROUND_PROCESSES ActivityManager.killBackgroundProcesses ActivityManagerNative.getDefault().killBackgroundProcesses() android.permission.RESTART_PACKAGES ActivityManager.restartPackage() android.permission.REORDER_TASKS ActivityManagerNative.getDefault().moveTaskToFront() ActivityManagerNative.getDefault().moveTaskToBack() ActivityManagerNative.getDefault().moveTaskBackwards() android.permission.RECEIVE_BOOT_COMPLETED Camera android.permission.CAMERA MediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA) Camera.takePicture() android.permission.RECORD_AUDIO MediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC) Settings android.permission.WRITE_APN_SETTINGS content://telephony/carriers/preferapn content://telephony/carriers
*创建缓存文件加权限<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" />*/ File file = new File(this.getCacheDir(), "temp.txt"); try { file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); bw.write("creat cache file"); bw.newLine(); bw.close(); } catch (IOException e) { System.out.println(e.getMessage()); } /*删除cache文件*/ File[] files = getCacheDir().listFiles(); for (File f : files) { f.delete(); }
/* * 文 件 名: DataCleanManager.java * 描 述: 主要功能有清除内/外缓存,清除数据库,清除sharedPreference,清除files和清除自定义目录 */ package com.archermind.DataClean; import java.io.File; import android.content.Context; import android.os.Environment; /** * 本应用数据清除管理器 */ public class DataCleanManager { /** * 清除本应用内部缓存(/data/data/com.xxx.xxx/cache) * * @param context */ public static void cleanInternalCache(Context context) { deleteFilesByDirectory(context.getCacheDir()); } /** * 清除本应用所有数据库(/data/data/com.xxx.xxx/databases) * * @param context */ public static void cleanDatabases(Context context) { deleteFilesByDirectory(new File("/data/data/" + context.getPackageName() + "/databases")); } /** * 清除本应用SharedPreference(/data/data/com.xxx.xxx/shared_prefs) * * @param context */ public static void cleanSharedPreference(Context context) { deleteFilesByDirectory(new File("/data/data/" + context.getPackageName() + "/shared_prefs")); } /** * 按名字清除本应用数据库 * * @param context * @param dbName */ public static void cleanDatabaseByName(Context context, String dbName) { context.deleteDatabase(dbName); } /** * 清除/data/data/com.xxx.xxx/files下的内容 * * @param context */ public static void cleanFiles(Context context) { deleteFilesByDirectory(context.getFilesDir()); } /** * 清除外部cache下的内容(/mnt/sdcard/android/data/com.xxx.xxx/cache) * * @param context */ public static void cleanExternalCache(Context context) { if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { deleteFilesByDirectory(context.getExternalCacheDir()); } } /** * 清除自定义路径下的文件,使用需小心,请不要误删。而且只支持目录下的文件删除 * * @param filePath */ public static void cleanCustomCache(String filePath) { deleteFilesByDirectory(new File(filePath)); } /** * 清除本应用所有的数据 * * @param context * @param filepath */ public static void cleanApplicationData(Context context, String... filepath) { cleanInternalCache(context); cleanExternalCache(context); cleanDatabases(context); cleanSharedPreference(context); cleanFiles(context); for (String filePath : filepath) { cleanCustomCache(filePath); } } /** * 删除方法 这里只会删除某个文件夹下的文件,如果传入的directory是个文件,将不做处理 * * @param directory */ private static void deleteFilesByDirectory(File directory) { if (directory != null && directory.exists() && directory.isDirectory()) { for (File item : directory.listFiles()) { item.delete(); } } } }