当前位置: 编程技术>移动开发
本页文章导读:
▪使用PackageManager跟ResolverInfo 使用PackageManager和ResolverInfo<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test01"
android:versionCode="1"
android:versionName="1.0" >
.........
▪ 初识Volley(4) 初识Volley(四)
main界面视图:
1.JsonRequest 没有有效的json地址,找了google的,400,请替换有效json地址就OK
2.使用的NetWorkImageView
3.使用的ImageRequest
主要说明下ImageRequest,ImageRequest中已经.........
▪ Qt调用摄像头(截取并封存图片) Qt调用摄像头(截取并保存图片) Qt如何调用系统摄像设备进行显示、截图、录制?
QCamera:系统摄像设备(摄像头)
QCameraViewfinder:摄像取景器部件
QCameraImageCapture:截图.........
[1]使用PackageManager跟ResolverInfo
来源: 互联网 发布时间: 2014-02-18
使用PackageManager和ResolverInfo
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test01" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.test01.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Activity01" android:label="@string/activity01" android:icon="@drawable/authentication_name_n"> <intent-filter > <action android:name="cxd.test.demo"/> </intent-filter> </activity> <activity android:name=".Activity02" android:label="@string/activity02" android:icon="@drawable/box_tj_h"> <intent-filter > <action android:name="cxd.test.demo"/> </intent-filter> </activity> <activity android:name=".Activity03" android:label="@string/activity03" android:icon="@drawable/box_tj"> <intent-filter > <action android:name="cxd.test.demo"/> </intent-filter> </activity> </application> </manifest>
这个是在manifest.xml配置文件中每个activity中配置了一个intent的行动,然后在MainActivity中
public class MainActivity extends ListActivity { private PackageManager mPackageManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPackageManager = getPackageManager(); List<ResolveInfo> activities = mPackageManager.queryIntentActivities( makeDemoActivityIntent(), PackageManager.GET_META_DATA); getListView().setAdapter( new ActivityListAdapter(this, activities, mPackageManager)); } protected Intent makeDemoActivityIntent() { Intent intent = new Intent(Constants.DEMO_ACTION); return intent; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub ActivityInfo resolveInfo = ((ResolveInfo) l.getItemAtPosition(position)).activityInfo; Intent intent = new Intent(); intent.setComponent(new ComponentName(resolveInfo.packageName, resolveInfo.name)); startActivity(intent); } }这里的
Intent intent = new Intent(Constants.DEMO_ACTION);参数就是<action android:name="cxd.test.demo"/>里的参数public class ActivityListAdapter extends BaseAdapter { private List<ResolveInfo> mData; private LayoutInflater mInflater; private PackageManager mPackageManager; public ActivityListAdapter(Context context, List<ResolveInfo> data, PackageManager packagetManager) { mData = data; mInflater = LayoutInflater.from(context); mPackageManager = packagetManager; } @Override public int getCount() { return mData.size(); } @Override public ResolveInfo getItem(int position) { return mData.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ResolveInfo resolveInfo = getItem(position); if (null == convertView) { convertView = mInflater.inflate( android.R.layout.simple_list_item_1, parent, false); } ((TextView) convertView) .setText(resolveInfo.loadLabel(mPackageManager)); ((TextView) convertView).setCompoundDrawables( resolveInfo.loadIcon(mPackageManager), null, null, null); return convertView; } }在ListActivity中点击每一个item然后就可以进入到activity中去,如果要做中文匹配的话在res文件里面新建values-zh-rCN.xml配置文件中新建string.xml文件,写中文版的
[2] 初识Volley(4)
来源: 互联网 发布时间: 2014-02-18
初识Volley(四)
main界面视图:
1.JsonRequest 没有有效的json地址,找了google的,400,请替换有效json地址就OK
2.使用的NetWorkImageView
3.使用的ImageRequest
主要说明下ImageRequest,ImageRequest中已经自带了缓存,只需要在代码的地方设置setShouldCache(true);就OK了
通过Volley中的代码,
public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), “volley”);
可以知道图片缓存在data/data/package/cache/volley下,缓存key直接使用的是URL,
通过代码
RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
可以知道使用的是DiskBasedCache这个类
可以打开这个类,能发现使用一个Map存储的信息
/** Map of the Key, CacheHeader pairs */ private final Map<String, CacheHeader> mEntries = new LinkedHashMap<String, CacheHeader>(16, .75f, true);
CacheHeader为DiskBasedCache中的内部类,其实就是一个bean,其中保存了key,length,etag,serverDate等等一系列做缓存是否更新校验的字段
RequestQueue 缓存处理是通过CacheDispatcher做缓存事件分发,同过entry.refreshNeeded()来确定是取缓存还是请求网络。
项目源码地址:http://download.csdn.net/detail/cj6585256/6407947
有人说下载缺少文件,把Volley源文件地址给上:http://download.csdn.net/detail/cj6585256/6407971
无网络时取的缓存图
[3] Qt调用摄像头(截取并封存图片)
来源: 互联网 发布时间: 2014-02-18
Qt调用摄像头(截取并保存图片)
Qt如何调用系统摄像设备进行显示、截图、录制?
Qt如何调用系统摄像设备进行显示、截图、录制?
QCamera:系统摄像设备(摄像头)
QCameraViewfinder:摄像取景器部件
QCameraImageCapture:截图部件
capture按钮:用于截图(截图后在右上角显示)
save按钮:用于保存截取后的图片(此处测试路径为:F:\a.jpg)
exit按钮:退出界面
效果如下:
代码如下:
#include "test_capture.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
{
this->resize(600, 400);
camera = new QCamera();
view_finder = new QCameraViewfinder();
camera_image_capture = new QCameraImageCapture(camera);
capture_button = new QPushButton();
save_button = new QPushButton();
exit_button = new QPushButton();
display_label = new QLabel();
QHBoxLayout *main_layout = new QHBoxLayout();
QVBoxLayout *v_layout = new QVBoxLayout();
display_label->setFixedSize(150, 150);
display_label->setScaledContents(true);
v_layout->addWidget(display_label);
v_layout->addStretch();
v_layout->addWidget(capture_button);
v_layout->addWidget(save_button);
v_layout->addWidget(exit_button);
main_layout->addWidget(view_finder);
main_layout->addLayout(v_layout);
connect(capture_button, &QPushButton::clicked, this, &Dialog::captureImage);
connect(save_button, &QPushButton::clicked, this, &Dialog::saveImage);
connect(exit_button, &QPushButton::clicked, this, &Dialog::close);
connect(camera_image_capture, &QCameraImageCapture::imageCaptured, this, &Dialog::displayImage);
camera_image_capture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
camera->setCaptureMode(QCamera::CaptureStillImage);
camera->setViewfinder(view_finder);
camera->start(); //启动摄像头
this->setLayout(main_layout);
this->translateLanguage();
}
Dialog::~Dialog()
{
}
void Dialog::translateLanguage()
{
this->setWindowTitle("testCapture");
capture_button->setText(tr("capture"));
save_button->setText(tr("save"));
exit_button->setText(tr("exit"));
}
void Dialog::displayImage(int id, QImage image)
{
display_label->setPixmap(QPixmap::fromImage(image));
}
void Dialog::captureImage()
{
//截图
camera_image_capture->capture();
}
void Dialog::saveImage()
{
const QPixmap *pixmap = display_label->pixmap();
if(pixmap)
{
pixmap->save("F:\\a.jpg");
}
}
最新技术文章: