我正在尝试使用像Vine或Instagram应用程序这样的视频实现列表.当列表项显示或完全可见时,他们播放视频播放的位置,并且当列表项被隐藏时视频暂停.我正在使用带有媒体播放器的textureview从url播放视频,并将其作为listler项目添加到recyclelerview中.以下是我的代码.
VideosAdapter类:
public class VideosAdapter extends RecyclerView.Adapter<VideosAdapter.ViewHolder> {
Context context;
private ArrayList<String> urls;
public static class ViewHolder extends RecyclerView.ViewHolder {
public LinearLayout layout;
public TextView textView;
public ViewHolder(View v) {
super(v);
layout = (LinearLayout) v.findViewById(R.id.linearLayout);
textView = (TextView) v.findViewById(R.id.textView);
}
}
public VideosAdapter(Context context, ArrayList<String> urls) {
this.context = context;
this.urls = urls;
}
// Create new views (invoked by the layout manager)
@Override
public VideosAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_main, …
Run Code Online (Sandbox Code Playgroud) android android-listview android-mediaplayer android-textureview android-recyclerview
我正在使用Android DownloadManager下载大型zip文件.我有listview显示所有zip文件的列表,用户可以点击项目开始下载.一次只能下载一个项目.当其他下载正在进行时,当新列表项开始下载时,我从队列中删除以前的下载ID.一切都很好.但有时我在LG g2设备OS 5.0.2上获得了ERROR_FILE_ERROR.这是代码:
Uri uri = Uri.parse(path);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setVisibleInDownloadsUi(false);
String localStorageBasePath = FileUtils.zipDirectory(context).getAbsolutePath() + File.separator + fileName;
Uri localStorageBasePathUri = Uri.fromFile(new File(localStorageBasePath));
request.setDestinationUri(localStorageBasePathUri);
Long downloadId = downloadManager.enqueue(request);
Run Code Online (Sandbox Code Playgroud)
它在其他设备上工作正常,包括nexus 5,samsung s3,note2,huawei等.当我开始下载文件时,它立即停止/失败,原因是DownloadManager.ERROR_FILE_ERROR.我试图删除/清理外部存储目录,确保它不是ERROR_INSUFFICIENT_SPACE错误等但它不起作用.有帮助吗?
我有一个活动加载片段A.片段A包含ListView,当单击列表项时,我加载另一个片段B代替片段A以显示列表视图项详细信息.在按钮上单击并按下设备后退按钮I它将加载前一个片段,即显示ListView的片段A. 所有这一切都运行正常,但我想在背景或按钮点击上加载动画片段A. 我是这样做的,但没有工作:
FragmentManager fsm = getSupportFragmentManager();
FragmentTransaction ftransaction = fsm.beginTransaction();
ftransaction.setCustomAnimations(R.anim.enter_from_left, R.anim.enter_from_left);
fsm.popBackStack();
ftransaction.commit();
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="700"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="700"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
Run Code Online (Sandbox Code Playgroud) 我已经按照 Google CameraX代码实验室来实现自定义相机。相机预览很好,但是当我在旋转图像捕获图像后拍摄图像时。我正在以纵向模式拍摄图像,但保存的图像是横向的。这是配置相机的方法
private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener(Runnable {
// Used to bind the lifecycle of cameras to the lifecycle owner
val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
// Preview
val preview = Preview.Builder()
.setTargetRotation(this.windowManager.defaultDisplay.rotation)
.build()
.also {
it.setSurfaceProvider(viewFinder.createSurfaceProvider())
}
imageCapture = ImageCapture.Builder()
.setTargetRotation(this.windowManager.defaultDisplay.rotation)
.build()
val imageAnalyzer = ImageAnalysis.Builder()
.build()
.also {
it.setAnalyzer(cameraExecutor, LuminosityAnalyzer { luma ->
Log.d(TAG, "Average luminosity: $luma")
})
}
// Select back camera as a default
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
try { …
Run Code Online (Sandbox Code Playgroud) android image-rotation android-orientation android-camera2 android-camerax
我已经实现了一个recyclerview,我在其中添加纹理视图作为列表项来播放来自url的视频.现在像藤蔓和Instagram应用程序我想播放视频,当它在recyclerview中可见,并在listitem离开屏幕时停止/暂停视频.以下是我的代码:
VideosAdapter类:
public class VideosAdapter extends RecyclerView.Adapter<VideosAdapter.ViewHolder> {
private static String TAG = "VideosAdapter";
Context context;
private ArrayList<String> urls;
RecyclerView recyclerView;
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextureView textureView;
public TextView textView;
public ViewHolder(View v) {
super(v);
textureView = (TextureView) v.findViewById(R.id.textureView);
textView = (TextView) v.findViewById(R.id.textView);
}
}
public VideosAdapter(Context context, RecyclerView recyclerView, final ArrayList<String> urls) {
this.context = context;
this.recyclerView = recyclerView;
this.urls = urls;
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { …
Run Code Online (Sandbox Code Playgroud) android-scrollview android-textureview android-recyclerview onscrollchanged
我正在尝试运行一个集成了android ndk 的库的演示应用程序.我已在Android工作室中导入此代码,并下载了ndk并将其与项目相关联.代码编译并成功构建.它会导致崩溃异常"初始化时抛出异常ljava lang unfisfiedlinkerror"失败:dlopen失败:无法找到"libtangram.so"引用的符号"_ZN7Tangram11setPositionEdd"......"
Application.mk:
APP_STL := c++_shared
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a x86 mips
APP_PLATFORM := android-19
Run Code Online (Sandbox Code Playgroud)
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := tangram
LOCAL_SRC_FILES := jniExports.cpp jniGenerated.cpp platform_android.cpp
LOCAL_LDLIBS := -llog
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
include $(BUILD_SHARED_LIBRARY)
Run Code Online (Sandbox Code Playgroud)
模块Gradle文件:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = GROUP
version = VERSION_NAME
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig { …
Run Code Online (Sandbox Code Playgroud) 可能重复的深层链接和多个应用程序实例。我已经在我的应用中实现了深度链接。我有 Splash 活动是启动器和 MainActivity 处理清单中定义的意图:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme">
<activity
android:name=".ActivitySplash"
android:configChanges="orientation|screenSize"
android:label="@string/app_name">
<intent-filter>
<!-- Launcher activity -->
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ActivityMain"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|screenSize"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.mywebsite.com"
android:pathPrefix="/something"
android:scheme="http" />
</intent-filter>
</activity>
<activity
android:name=".ActivitySignIn"
android:configChanges="screenSize|orientation" />
<activity android:name=".ActivitySignUp" />
</application>
Run Code Online (Sandbox Code Playgroud)
我已经设置启动模式 singleTask 来处理 onNewIntent()。现在我想要实现的是,如果用户从 DeepLinking 打开活动并且 MainActivity 中已经有一些任务在进行,我会提示用户一个对话框,要么他想取消当前任务并开始新任务(来自深度链接)。问题是如果我从 MainActivity 打开另一个活动并且用户来自 DeepLinking Intent。然后它会杀死第二个活动并直接打开 MainActivity。我想要实现的是,如果应用程序/活动未运行,则来自 DeepLink 的 …
android single-instance android-manifest android-intent android-activity
示例android api demo中的Fingerpaint示例不会通过触摸屏幕上的手指来绘制点/点.在代码中他们使用Path来绘制线条,有没有办法用路径绘制圆圈或点?
public class MyView extends View {
// int bh = originalBitmap.getHeight();
// int bw = originalBitmap.getWidth();
public MyView(Context c, int w, int h) {
super(c);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
// Bitmap mBitmap =
// Bitmap.createScaledBitmap(originalBitmap,200,200,true);
mCanvas = new Canvas(mBitmap);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
//mBitmapPaint.setColor(Color.YELLOW);
//mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
// mBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888);
// mCanvas = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用新的Facebook sdk 4.5版跟踪ProfileTracker类的用户配置文件.当用户在我的应用程序中使用Facebook登录(并且Facebook本机应用程序安装在设备中)时,它将使用本机应用程序中的当前用户帐户成功登录.但现在,如果用户从设备中的本机Facebook应用程序注销,并使用另一个用户帐户登录,而不是之前的用户帐户.我希望我的应用程序收到通知,现在用户已在原生应用中更改了他的帐户/个人资料.为了实现我正在使用以下代码:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_homescreen);
uIint();
LoginManager.getInstance().registerCallback(callbackManager, this);
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
if (oldProfile != null) {
Log.i(getClass().getSimpleName(), "profile oldProfile: " + oldProfile.getFirstName());
}
if (currentProfile != null) {
Log.i(getClass().getSimpleName(), "profile currentProfile: " + currentProfile.getFirstName());
}
}
};
profileTracker.startTracking();
if(profileTracker.isTracking())
Log.i(getClass().getSimpleName(), "profile currentProfile Tracking: " + "yes");
else
Log.i(getClass().getSimpleName(), "profile currentProfile Tracking: " + "no");
}
@Override …
Run Code Online (Sandbox Code Playgroud) 我能够使用google plus登录并获取我谷歌加圈子中所有人的列表但现在我还想获得我圈子中所有人的电子邮件地址是否有办法做到这一点?我尝试过这段代码,但它不起作用.
public void onPeopleLoaded(ConnectionResult status, final PersonBuffer personBuffer,
String nextPageToken)
{
if (status.getErrorCode() == ConnectionResult.SUCCESS)
{
try
{
//Add all friends ids in an arraylist
int count = personBuffer.getCount();
//Loop through all the ids of google plus friends
for (int i = 0; i < count; i++)
{
//mListItems.add(personBuffer.get(i).getDisplayName());
//mListIds.add(personBuffer.get(i).getId());
friends_gplus_Ids += personBuffer.get(i).getId() + ",";
//Log.d("Emails", personBuffer.get(i).getOrganizations().toString());
//personBuffer.get(i).getEmails().size();
if((personBuffer.get(i).getEmails().size() > 0))
{
Log.d("Emails", personBuffer.get(i).getEmails().get(0).toString());
}
else
{
Log.d("Emails", "Null");
}
}
}
finally
{
personBuffer.close();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个RecyclerView,其中包含Horizontal RecyclerView和Vertical Recyclerview。我对如何同时管理两者的数据模型感到困惑。这是我的代码,后面是这个例子
public class HomeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int VIEW_TYPE_DESIGN_TYPES = 0;
private final int VIEW_TYPE_DESIGNS = 1;
private Context context;
private ArrayList<Object> feeds;
public HomeAdapter(Context context, ArrayList<Object> feeds) {
this.context = context;
this.feeds = feeds;
}
@Override
public int getItemViewType(int position) {
if (position == 0)
return VIEW_TYPE_DESIGN_TYPES;
if (position == 1)
return VIEW_TYPE_DESIGNS;
return -1;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View view;
RecyclerView.ViewHolder holder;
switch (viewType) …
Run Code Online (Sandbox Code Playgroud) 我已经实现了Android 和 MJPEG
并且还实现了异步和认证来运行这里提到的它。现在我已经设法运行 jpeg 视频流,但问题是它在运行流时一直闪烁。它不断地起落。我认为这可能是框架的问题。任何人都知道如何处理这个问题。这是我实现的完整代码:
MjpegSample.java
public class MjpegSample extends Activity {
private static final boolean DEBUG=true;
private static final String TAG = "MJPEG";
private MjpegView mv;
private static final int MENU_QUIT = 1;
String URL;
MjpegInputStream inputStream;
/* Creates the menu items */
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_QUIT, 0, "Quit");
return true;
}
/* Handles item selections */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_QUIT:
finish();
return true;
}
return …
Run Code Online (Sandbox Code Playgroud)