修改相机组件界面
修改相机组件界面需要继承 TuCameraFragment 类并在子类中重写 loadView() 方法,在 loadView() 方法中使用 getViewById() 方法找到新添加的视图,然后对该视图进行操作。
在布局文件中添加视图
相机组件界面布局文件是 tusdk_impl_component_camera_fragment.xml,放在 TuSDK/res/layout 目录下,建议用户修改界面的时候不要直接在该文件上做修改,而是把该文件复制到自己的项目下的 res/layout 目录中并重命名,比如命名为 custom_camera_fragment_layout.xml,这样可以防止将来升级 SDK 的时候造成覆盖。
找到自己项目下的 custom_camera_fragment_layout.xml 文件,在合适位置添加上自己想要显示的视图。
在子类中重写 loadView() 方法
新建一个类 CustomCameraFragment 继承 TuCameraFragment,并在该类中重写 loadView() 方法,在此方法中找到添加的视图并对其进行操作。
// 子类继承TuCameraFragment
public class CustomCameraFragment extends TuCameraFragment
{
/**
* 布局ID
*/
public static int getLayoutId()
{
return R.layout.custom_camera_fragment_layout;
}
@Override
protected void loadView(ViewGroup view)
{
super.loadView(view);
// 在这里使用 getViewById()方法找到新添加的视图
}
}设置相机属性并开启相机
这里需要将子类 CustomCameraFragment 指定为相机组件的控制器类型,将custom_camera_fragment_layout.xml 指定为相机组件的布局 ID,然后再开启相机。
开启相机的步骤跟正常打开相机是一样的,都是先获取 TuCameraFragment 的实例然后打开。
打开相机完整代码如下:
TuCameraOption option = new TuCameraOption(); // 控制器类型 option.setComponentClazz(CustomCameraFragment.class); // 设置根视图布局资源ID option.setRootViewLayoutId(CustomCameraFragment.getLayoutId()); TuCameraFragment fragment = option.fragment(); // 开启相机 presentModalNavigationActivity(fragment, true);
修改照片美化组件界面
修改照片美化组件界面需要新建一个类继承 TuEditMultipleFragment 类,并在子类中重写 loadView() 方法,在该方法中使用 getViewById(int id) 找到用户添加的视图。
在布局文件中添加视图
照片美化组件界面布局文件是 tusdk_impl_component_edit_multiple_fragment.xml,放在 TuSDK/res/layout目录下,建议用户修改界面的时候不要直接在该文件上做修改,而是把该文件复制到自己的项目下的 res/layout目录中并重命名,比如命名为 custom_multiple_fragment_layout.xml,这样可以防止将来升级 SDK 的时候造成覆盖。
找到自己项目下的 custom_multiple_fragment_layout.xml 文件,在合适位置添加上自己想要显示的视图。
在子类中重写 loadView() 方法
新建一个类 CustomMultipleFragment 继承 TuEditMultipleFragment,并在该类中重写 loadView() 方法,在此方法中找到添加的视图并对其进行操作。
// 子类继承 TuEditMultipleFragment
public class CustomMultipleFragment extends TuEditMultipleFragment
{
/**
* 布局ID
*/
public static int getLayoutId()
{
return R.layout.custom_multiple_fragment_layout;
}
@Override
protected void loadView(ViewGroup view)
{
super.loadView(view);
// 在这里使用 getViewById()方法找到新添加的视图
}
}指定控制器类型和根视图资源ID
当把子类和布局文件都写好之后,下面就是把子类和布局文件指定给照片美化组件了。
首先需要获得一个照片美化组件的对象,如下所示:
TuEditMultipleComponent component = null;
// 组件委托
TuSdkComponentDelegate delegate = new TuSdkComponentDelegate()
{
@Override
public void onComponentFinished(TuSdkResult result, Error error, TuFragment lastFragment)
{
TLog.d("onEditMultipleComponentReaded: %s | %s", result, error);
}
};
component = TuSdkGeeV1.editMultipleCommponent(MainActivity.this, delegate);MainActivity 是用户自己的继承自 android.app.Activity 的类,delegate 是对照片美化组件设置的组件委托。
然后是给照片美化组件指定控制器类型和根视图资源ID,如下所示:
// 指定控制器类型 component.componentOption().editMultipleOption().setComponentClazz(CustomMultipleFragment.class); // 指定根视图资源ID component.componentOption().editMultipleOption().setRootViewLayoutId(R.layout.custom_multiple_fragment_layout);
最后给组件设置图片并开启:
// 设置图片 component.setImage(result.image) // 设置系统照片 .setImageSqlInfo(result.imageSqlInfo) // 设置临时文件 .setTempFilePath(result.imageFile) // 在组件执行完成后自动关闭组件 .setAutoDismissWhenCompleted(true) // 开启组件 .showComponent();
随时随地看视频