Is there a panorama open-source solution for the Android camera app?
I came across these options:
panoramagl-android
WideAnglePanoramaModule.java
but they look a little old and have no support, is there anything newer?
I also came across this page:
But there is not much documentation about it that I could find.
I would like to get a full solution including capturing the images, stitching and displaying.
Look at this article:
https://itnext.io/android-360-panorama-cedbfb47a9e
The thing that i dont like is that all images are from assets. I did it with image from firebase:
add dependancy:
dependencies {
/*
* Google VR SDK
* Release version: https://github.com/googlevr/gvr-android-sdk/releases
* */
implementation 'com.google.vr:sdk-panowidget:1.180.0'
implementation 'com.github.silvestrpredko:dot-progress-bar:1.1'
}
add class
public class SimpleVrPanoramaActivity extends Activity {
#BindView(R.id.progressBar2)
DotProgressBar dotProgressBar;
#BindView(R.id.pano_view)
VrPanoramaView panoWidgetView;
private String bar_panorama1;
private String mPost_key = null;
private Bitmap[] bitmaps = new Bitmap[1];
private DatabaseReference databaseReference;
private VrPanoramaView.Options panoOptions = new VrPanoramaView.Options();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_panorama);
ButterKnife.bind(this);
if (getIntent().getExtras() != null) {
mPost_key = getIntent().getExtras().getString("bar_id");
}
panoOptions.inputType = VrPanoramaView.Options.TYPE_MONO;
databaseReference = FirebaseDatabase.getInstance().getReference().child("bars").child(mPost_key).child("pano");
fetchPanorama();
}
private void fetchPanorama() {
databaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
bar_panorama1 = dataSnapshot.child("i1").getValue(String.class);
glideImage(bar_panorama1);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(SimpleVrPanoramaActivity.this, "Проверьте подключение к интернету!", Toast.LENGTH_LONG).show();
}
});
}
public void glideImage(String bar_panorama) {
Glide.with(SimpleVrPanoramaActivity.this)
.asBitmap()
.load(bar_panorama)
.into(new CustomTarget<Bitmap>() {
#Override
public void onLoadFailed(#Nullable Drawable errorDrawable) {
dotProgressBar.setVisibility(View.GONE);
}
#Override
public void onResourceReady(#NonNull Bitmap resource, #Nullable Transition<? super Bitmap> transition) {
bitmaps[0] = resource;
panoWidgetView.loadImageFromBitmap(bitmaps[0], panoOptions);
dotProgressBar.setVisibility(View.GONE);
}
#Override
public void onLoadCleared(#Nullable Drawable placeholder) {
}
});
}
#Override
protected void onPause() {
panoWidgetView.pauseRendering();
super.onPause();
}
#Override
protected void onResume() {
super.onResume();
panoWidgetView.resumeRendering();
}
#Override
protected void onDestroy() {
// Destroy the widget and free memory.
panoWidgetView.shutdown();
super.onDestroy();
}
}
add xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/colorPrimary"
tools:context=".aktau.panorama.PanoramaGLActivity">
<include
android:id="#+id/toolbar_pano"
layout="#layout/toolbar_pano"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<View
android:id="#+id/yellow_layer"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorOrange"
android:layout_below="#+id/toolbar_pano"
/>
<com.google.vr.sdk.widgets.pano.VrPanoramaView
android:id="#+id/pano_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/yellow_layer"/>
<com.github.silvestrpredko.dotprogressbar.DotProgressBar
android:id="#+id/progressBar2"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_below="#+id/toolbar_pano"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
app:amount="3"
android:layout_centerHorizontal="true"
app:animationDirection="right"
app:duration="#android:integer/config_shortAnimTime"
app:endColor="#color/colorPrimaryDark"
app:startColor="#color/colorLightBlue" />
</RelativeLayout>
Related
Main Activity
public class MainActivity extends AppCompatActivity implements LocationEngineListener, PermissionsListener{
private MapView mapView;
private MapboxMap map;
private PermissionsManager permissionsManager;
private LocationLayerPlugin locationPlugin;
private LocationEngine locationEngine;
private Location originLocation;
private Marker destinationMarker;
private LatLng originCoord;
private LatLng destinationCoord;
private Point originPosition;
private Point destinationPosition;
private DirectionsRoute currentRoute;
private static final String TAG = "DirectionsActivity";
private NavigationMapRoute navigationMapRoute;
private Button button;
private ArrayList <String> mNames=new ArrayList<>();
private ArrayList <String> mImages=new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this,getString(R.string.token));
setContentView(R.layout.activity_main);
mapView=(MapView)findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
button = findViewById(R.id.startnav);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Point origin = originPosition;
Point destination = destinationPosition;
// Pass in your Amazon Polly pool id for speech synthesis using Amazon Polly
// Set to null to use the default Android speech synthesizer
String awsPoolId = null;
boolean simulateRoute = true;
NavigationViewOptions options = NavigationViewOptions.builder()
.origin(origin)
.destination(destination)
.awsPoolId(awsPoolId)
.shouldSimulateRoute(simulateRoute)
.build();
// Call this method with Context from within an Activity
NavigationLauncher.startNavigation(MainActivity.this, options);
}
});
mapView.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(final MapboxMap mapboxMap) {
map = mapboxMap;
enableLocationPlugin();
originCoord = new LatLng(originLocation.getLatitude(), originLocation.getLongitude());
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
#Override
public void onMapClick(#NonNull LatLng point) {
button.setEnabled(true);
button.setBackgroundResource(R.drawable.button_press);
if (destinationMarker != null) {
mapboxMap.removeMarker(destinationMarker);
}
destinationCoord = point;
destinationMarker = mapboxMap.addMarker(new MarkerOptions()
.position(destinationCoord)
);
destinationPosition = Point.fromLngLat(destinationCoord.getLongitude(), destinationCoord.getLatitude());
originPosition = Point.fromLngLat(originCoord.getLongitude(), originCoord.getLatitude());
getRoute(originPosition, destinationPosition);
}
});
}
});
getImages();
}
private void getImages() {
Log.d(TAG, "initImageBitmaps: preparing bitmaps");
mImages.add("https://c1.staticflickr.com/5/4636/25316407448_de5fbf183d_o.jpg");
mNames.add("Havasu Falls");
mImages.add("https://i.redd.it/tpsnoz5bzo501.jpg");
mNames.add("Trondheim");
mImages.add("https://i.redd.it/qn7f9oqu7o501.jpg");
mNames.add("Portugal");
mImages.add("https://i.redd.it/j6myfqglup501.jpg");
mNames.add("Rocky Mountain National Park");
mImages.add("https://i.redd.it/0h2gm1ix6p501.jpg");
mNames.add("Mahahual");
mImages.add("https://i.redd.it/k98uzl68eh501.jpg");
mNames.add("Frozen Lake");
mImages.add("https://i.redd.it/glin0nwndo501.jpg");
mNames.add("White Sands Desert");
mImages.add("https://i.redd.it/obx4zydshg601.jpg");
mNames.add("Austrailia");
mImages.add("https://i.imgur.com/ZcLLrkY.jpg");
mNames.add("Washington");
InitRecyclerView();
}
private void InitRecyclerView() {
Log.d(TAG, "InitRecyclerView: init recyclerview");
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
RecyclerView recyclerView=findViewById(R.id.myrecyclerview);
recyclerView.setLayoutManager(linearLayoutManager);
MainAdapter adapter=new MainAdapter(this,mNames,mImages);
recyclerView.setAdapter(adapter);
}
#SuppressWarnings( {"MissingPermission"})
private void enableLocationPlugin() {
// verifica daca are permission si le cere
if (PermissionsManager.areLocationPermissionsGranted(this)) {
// Create an instance of LOST location engine
initializeLocationEngine();
locationPlugin = new LocationLayerPlugin(mapView, map, locationEngine);
locationPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
} else {
permissionsManager = new PermissionsManager( this);
permissionsManager.requestLocationPermissions(this);
}
}
#SuppressWarnings( {"MissingPermission"})
private void initializeLocationEngine() {
locationEngine = new LostLocationEngine(MainActivity.this);
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.activate();
Location lastLocation = locationEngine.getLastLocation();
if (lastLocation != null) {
originLocation = lastLocation;
setCameraPosition(lastLocation);
} else {
locationEngine.addLocationEngineListener(this);
}
}
private void setCameraPosition(Location location) {
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 13));
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
#Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
}
#Override
public void onPermissionResult(boolean granted) {
if (granted) {
enableLocationPlugin();
} else {
finish();
}
}
#Override
#SuppressWarnings( {"MissingPermission"})
public void onConnected() {
locationEngine.requestLocationUpdates();
}
#Override
public void onLocationChanged(Location location) {
if (location != null) {
originLocation = location;
setCameraPosition(location);
locationEngine.removeLocationEngineListener(this);
}
}
#Override
#SuppressWarnings( {"MissingPermission"})
protected void onStart() {
super.onStart();
if (locationEngine != null) {
locationEngine.requestLocationUpdates();
}
if (locationPlugin != null) {
locationPlugin.onStart();
}
mapView.onStart();
}
#Override
protected void onStop() {
super.onStop();
if (locationEngine != null) {
locationEngine.removeLocationUpdates();
}
if (locationPlugin != null) {
locationPlugin.onStop();
}
mapView.onStop();
}
#Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
if (locationEngine != null) {
locationEngine.deactivate();
}
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
#Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
private void getRoute(Point origin, Point destination) {
NavigationRoute.builder()
.accessToken(Mapbox.getAccessToken())
.origin(origin)
.destination(destination)
.build()
.getRoute(new Callback<DirectionsResponse>() {
#Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
// You can get the generic HTTP info about the response
Log.d(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().routes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}
currentRoute = response.body().routes().get(0);
// Draw the route on the map
if (navigationMapRoute != null) {
navigationMapRoute.removeRoute();
} else {
navigationMapRoute = new NavigationMapRoute(null, mapView, map, R.style.NavigationMapRoute);
}
navigationMapRoute.addRoute(currentRoute);
}
#Override
public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
Log.e(TAG, "Error: " + throwable.getMessage());
}
});
}
}
And the MainAdapter
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
private static final String TAG="MainAdapter";
private ArrayList <String> mNames=new ArrayList<>();
private ArrayList <String> mImages=new ArrayList<>();
private Context mContext;
public MainAdapter(Context context , ArrayList<String> images, ArrayList<String> names) {
mNames=names;
mImages=images;
mContext=context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d(TAG, "onCreateViewHolder: called ");
View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_listitem,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ViewHolder holder, final int position) {
Log.d(TAG, "onBindViewHolder: called");
Glide.with(mContext)
.asBitmap()
.load(mImages.get(position))
.into(holder.image);
holder.name.setText(mNames.get(position));
holder.image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: clicked on a image"+mNames.get(position));
Toast.makeText(mContext,mNames.get(position),Toast.LENGTH_SHORT).show();
}
});
}
#Override
public int getItemCount() {
return mImages.size();
}
public class ViewHolder extends RecyclerView.ViewHolder
{
CircleImageView image;
TextView name;
public ViewHolder(View itemView) {
super(itemView);
image=itemView.findViewById(R.id.image_view);
name=itemView.findViewById(R.id.name);
}
}
}
This is activitymain layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matei.meetup.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/myrecyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="#+id/mapView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
mapbox:mapbox_cameraTargetLat="38.9098"
mapbox:mapbox_cameraTargetLng="-77.0295"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10"
mapbox:mapbox_cameraZoom="12" >
</com.mapbox.mapboxsdk.maps.MapView>
<Button
android:id="#+id/startnav"
android:layout_width="316dp"
android:layout_height="41dp"
android:layout_margin="20px"
android:background="#drawable/button_unpressed"
android:padding="5px"
android:text="Start navigation"
android:textColor="#color/mapboxWhite"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintLeft_toLeftOf="parent"
mapbox:layout_constraintRight_toRightOf="parent"
mapbox:layout_constraintTop_toBottomOf="#+id/mapView"
mapbox:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
And here is the other layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp">
<android.support.v7.widget.CardView
android:layout_width="100dp"
android:layout_height="100dp"
app:cardCornerRadius="4dp"
app:cardElevation="1dp"
app:cardMaxElevation="2dp"
android:layout_centerInParent="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"
android:id="#+id/image_view"
android:src="#mipmap/ic_launcher"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:text="Chestie"
android:layout_below="#+id/image_view"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_marginTop="5dp"
android:textColor="#000"
android:layout_marginBottom="5dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
The app does not crash on runtime, it only displays the map without the RecyclerView. In my gradle file i inlcuded the dependencies i needed. I tried messing around with the gradle file, nothing seems to work. In my logcat I have the following java.io.FileNotFoundException-No such file or directory.
Problem in library de.hdodenhof.circleimageview.CircleImageView. check this
https://github.com/hdodenhof/CircleImageView/issues/121
If you need to circle imageview you can use glide transformation with imageview
https://bumptech.github.io/glide/doc/transformations.html
Example glide v4:
RequestOptions options = new RequestOptions();
options.CircleCrop();
Glide.with(fragment)
.load(url)
.apply(options)
.into(imageView);
I have been working on an android project in which I have used YouTube API and Firebase as a database, I also used recyclerView in it but my videos from Firebase database are not showing in the application, I have implemented it correctly I guess but there is something wrong with it, please help.
I am using Android Studio
YouTube Firebase Adapter java class:
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.youtube_videos);
YDatabaseReference = FirebaseDatabase.getInstance().getReference().child("youT");
YouRecycler = (RecyclerView)findViewById(R.id.Youtube_recycler);
}
#Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<post2youtube, YoutubeViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<post2youtube, YoutubeViewHolder>(
post2youtube.class,
R.layout.youtube_videos_card,
YoutubeViewHolder.class,
YDatabaseReference
) {
#Override
protected void populateViewHolder(YoutubeViewHolder viewHolder, post2youtube model, int position) {
viewHolder.setYoutube(model.getYoutubing());
}
};
YouRecycler.setAdapter(firebaseRecyclerAdapter);
}
public static class YoutubeViewHolder extends RecyclerViewPager.ViewHolder {
View yView;
public YoutubeViewHolder(View itemView) {
super(itemView);
yView = itemView;
}
public void setYoutube(final String youtubing){
final YouTubePlayerView youPlay = (YouTubePlayerView) yView.findViewById(R.id.youtuber);
youPlay.initialize("SOME KEY",
new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo(youtubing);
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult youTubeInitializationResult) {
}
});
}
Getter and setters class :
public class post2youtube {
private String youtubing;
public post2youtube(){
}
public post2youtube(String youtubing) {
this.youtubing = youtubing;
}
public String getYoutubing() {
return youtubing;
}
public void setYoutubing(String youtubing) {
this.youtubing = youtubing;
}
}
RecyclerView xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/Youtube_recycler"/>
</LinearLayout>
CardView xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtuber"
android:layout_width="match_parent"
android:layout_height="200dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
I am facing an issue in using the FirebaseRecyclerAdapter.
The firebase realtime database structure is as follows:
What I'm trying to do here is,
Get only the key's from data present in the "MainGroup" part of the firebase realtime database.
So to do that, I've created a model class named RecyclerDataGetSetCLass
and one viewholder class named RecyclerDataGetSetClassViewHolder
but i am getting an error saying
com.google.firebase.database.DatabaseException: Can't convert object
of type java.lang.String to type
com.example.talarir.mapproject.NonAdminClasses.RecyclerDataGetSetCLass
The Activity classes and other java files are as follows:
1) NonAdminACtivity.java //which contains the viewholder class
public class NonAdminACtivity extends AppCompatActivity implements View.OnClickListener {
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
public Button saveLocationBtn,getLocationBtn;
public RecyclerView nonAdminRecyclerView;
private Boolean flag=false;
private DatabaseReference mFirebaseDatabase;
private FirebaseDatabase mFirebaseInstance;
private DatabaseReference mFirebaseDatabase1;
private FirebaseDatabase mFirebaseInstance1;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_non_admin_activity);
mFirebaseInstance1 = FirebaseDatabase.getInstance();
mFirebaseDatabase1 = mFirebaseInstance1.getReference("MainGroup");
nonAdminRecyclerView= (RecyclerView) findViewById(R.id.recycler_view_fragment_one);
nonAdminRecyclerView.setHasFixedSize(true);
nonAdminRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
flag=true;
Log.d("CooActivity", "onAuthStateChanged:signed_in:" + user.getUid());
Toast.makeText(getApplicationContext(),"done",Toast.LENGTH_SHORT).show();
}
else
{
// User is signed out
Log.d("CooActivity", "onAuthStateChanged:signed_out");
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
finish();
}
}
};
}
#Override
public void onStart()
{
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
saveLocationBtn= (Button) findViewById(R.id.saveLocationOfUser);
saveLocationBtn.setOnClickListener(this);
getLocationBtn= (Button) findViewById(R.id.getLocationOfUser);
getLocationBtn.setOnClickListener(this);
FirebaseRecyclerAdapter<RecyclerDataGetSetCLass,RecyclerDataGetSetClassViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<RecyclerDataGetSetCLass, RecyclerDataGetSetClassViewHolder>(
RecyclerDataGetSetCLass.class,
R.layout.each_list_non_admin,
RecyclerDataGetSetClassViewHolder.class,
mFirebaseDatabase1
) {
#Override
protected void populateViewHolder(RecyclerDataGetSetClassViewHolder viewHolder, RecyclerDataGetSetCLass model, int position)
{
viewHolder.setMainGroupName(model.getMainGroupName());
}
};
nonAdminRecyclerView.setAdapter(firebaseRecyclerAdapter);
}
public static class RecyclerDataGetSetClassViewHolder extends RecyclerView.ViewHolder
{
View mView;
public RecyclerDataGetSetClassViewHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setMainGroupName(String mainGroupName)
{
TextView textView= (TextView) mView.findViewById(R.id.textViewRecyclerViewNonAdmin);
textView.setText(mainGroupName);
}
}
#Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
#Override
protected void onDestroy() {
FirebaseAuth.getInstance().signOut();
super.onDestroy();
}
#Override
public void onClick(View v)
{
if (v.getId()==R.id.saveLocationOfUser)
{
if (flag)
{
saveUserLocation_NonAdminActivity();
}
else
{
Toast.makeText(this,"firebase not ready",Toast.LENGTH_SHORT).show();
}
}
if (v.getId()==R.id.getLocationOfUser)
{
retrieveUserLocation_NonAdminActivity();
}
}
private void retrieveUserLocation_NonAdminActivity()
{
CreationOfUserClass creationOfUserClass=new CreationOfUserClass(this);
creationOfUserClass.retrieveUserDataFromFireBase(mFirebaseDatabase,mFirebaseInstance);
}
private void saveUserLocation_NonAdminActivity()
{
FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
final CreationOfUserClass creationOfUserClass=new CreationOfUserClass(this);
creationOfUserClass.createUsers(user, mFirebaseDatabase,mFirebaseInstance);
}
}
2) RecyclerDataGetSetCLass //The model class
public class RecyclerDataGetSetCLass
{
private String mainGroupName;
public RecyclerDataGetSetCLass()
{
}
public RecyclerDataGetSetCLass(String mainGroupName)
{
this.mainGroupName=mainGroupName;
}
public String getMainGroupName() {
return mainGroupName;
}
public void setMainGroupName(String mainGroupName) {
this.mainGroupName = mainGroupName;
}
}
3) activity_non_admin_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_non_admin_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.talarir.mapproject.NonAdminACtivity">
<Button
android:text="SaveLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/saveLocationOfUser" />
<Button
android:text="getLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/getLocationOfUser" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_fragment_one"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
4) each_list_non_admin.xml //the layout to be inflated for each recycler list element
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
xmlns:card_view="http://schemas.android.com/tools">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textViewRecyclerViewNonAdmin"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
The error log is as follows :
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.talarir.mapproject.NonAdminClasses.RecyclerDataGetSetCLass
at com.google.android.gms.internal.zzbtg.zze(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzb(Unknown Source)
at com.google.android.gms.internal.zzbtg.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:151)
at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:140)
at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:183)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6308)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6341)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5287)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5550)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5392)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5388)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2149)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1533)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1496)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:593)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3535)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3264)
at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1633)
at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:341)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:616)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6209)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
D/AppTracker: App Event: crash
I/Process: Sending signal. PID: 29821 SIG: 9
Application terminated.
Kindly assist me to get through this issue.
The value of each item you're displaying is a single string (-K....). You're trying to read an entire class out of the value, and that simply won't work.
final FirebaseRecyclerAdapter<RecyclerDataGetSetCLass,RecyclerDataGetSetClassViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<RecyclerDataGetSetCLass, RecyclerDataGetSetClassViewHolder>(
String.class,
R.layout.each_list_non_admin,
RecyclerDataGetSetClassViewHolder.class,
mFirebaseDatabase1
) {
#Override
protected void populateViewHolder(RecyclerDataGetSetClassViewHolder viewHolder, String model, int position)
{
String key = adapter.getRef(position).getKey();
viewHolder.setMainGroupName(key);
}
};
In this snippet I look up the key of the item being shown, which is likely the value that you're looking for.
I read some essays about releasing memories for Bitmap objects. I create a sample to test this problem as below.
MainActivity class:
public class MainActivity extends Activity {
private Bitmap bitmap;
private InputStream inputStream;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onStart() {
super.onStart();
try {
inputStream = getAssets().open("image1.jpg");
bitmap = BitmapFactory.decodeStream(inputStream);
}catch(Exception e){
Log.v("hoabao91", e.getMessage());
}
}
#Override
protected void onPause() {
super.onPause();
try {
inputStream.close();
inputStream = null;
bitmap.recycle();
bitmap = null;
}catch(Exception e){
Log.v("hoabao91", e.getMessage());
}
}
public void click(View view){
startActivity(new Intent(this, TestActivity.class));
}
}
TestActivity class:
public class TestActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
activity_main view:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:onClick="click"/>
</LinearLayout>
activity_test:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hoa.test2.TestActivity">
</RelativeLayout>
I use android debug tool to track allocated memory
This is a status when I deploy the app
The system allocate to all objects including bitmap object 11.96 MB
Then I click the button "Submit" to go to TestActivity, the method onPause() will be called and the bitmap object will be release by recycle(). But status of allocated memory doesn't decrease. In contrast, it increase a little more (11.99 MB)!
Someone help me with explaining about that or giving me a solution to decrease allocated memory. To avoid leak of memory for large app.
Ok, so, i want to make something like this:
http://postimg.org/image/qs3okxitf/
Now, im using zbarscannerview like this:
public class BarKodScreen extends AppCompatActivity implements ZBarScannerView.ResultHandler {
private ZBarScannerView mView;
private BarcodeFormat barcodeFormatEAN13, barcodeFormatEAN8;
private List<BarcodeFormat> listaZaFormat = new ArrayList<BarcodeFormat>();
private ImageView img;
private LinearLayout lejout;
private View kamera;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_barkod);
mView = new ZBarScannerView(this);
lejout = (LinearLayout) findViewById(R.id.cameraPreview);
img = (ImageView) findViewById(R.id.cameraImageView);
kamera = (View) findViewById(R.id.zaKameru);
kamera = mView;
lejout.addView(kamera);
lejout.addView(kamera);
lejout.removeView(img);
lejout.addView(img);
barcodeFormatEAN13 = BarcodeFormat.EAN13;
barcodeFormatEAN8 = BarcodeFormat.EAN8;
listaZaFormat.add(barcodeFormatEAN13);
listaZaFormat.add(barcodeFormatEAN8);
mView.setFormats(listaZaFormat);
}
#Override
public void onResume() {
super.onResume();
mView.setResultHandler(this); // Register ourselves as a handler for scan results.
mView.startCamera(); // Start camera on resume
}
#Override
public void onPause() {
super.onPause();
mView.stopCamera(); // Stop camera on pause
}
#Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v("GetCOntent", rawResult.getContents()); // Prints scan results
barKodZahtev(rawResult.getContents());
}
}
and my xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cameraPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/zaKameru"
android:layout_width="match_parent"
android:layout_height="150dp"/>
<ImageView
android:id="#+id/cameraImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.6"
android:src="#drawable/share" />
</LinearLayout>
What I dont understand is how to add the image(text from the screenshot) as a child view for my zbarscannerView.
Check out their rapository on github, they have something there.