android


How to do this thing right? [duplicate]


This question already has an answer here:
NavigationView get/find header layout
4 answers
In android how to set navigation drawer header image and name programmatically in class file?
8 answers
What can i do for this
Error occured this : java.lang.IllegalArgumentException: Target must not be null.
Picasso.with(this).load("https://lh4.googleusercontent.com/-MtNPyplAAVI/AAAAAAAAAAI/AAAAAAAACw4/be7EgD6UmTA/s96-c/photo.jpg").into(imageView);
Below is my code
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private TextView barcoderesult;
private TextView username,email;
private DatabaseReference databaseReference;
public static final int CAMERA_REQUEST_CODE=10;
private String TAG;
public static int item_quantity;
ImageView imageView;
RoundImage roundImage;
FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
imageView=(ImageView)findViewById(R.id.user_image);
try {
URL url=new URL(user.getPhotoUrl().toString());
Picasso.with(this).load("https://lh4.googleusercontent.com/-MtNPyplAAVI/AAAAAAAAAAI/AAAAAAAACw4/be7EgD6UmTA/s96-c/photo.jpg").into(imageView);
}
catch (Exception e){
System.out.println("Error occured this : "+ e);
}
mAuth=FirebaseAuth.getInstance();
mAuthListener=new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser()==null){
startActivity(new Intent(Home.this,MainActivity.class));
}
}
};
// For setting user name and email in header
//FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){
String name=user.getDisplayName();
String usr_email=user.getEmail();
/*User database registration*/
databaseReference= FirebaseDatabase.getInstance().getReference();
UserInformation userInformation=new UserInformation(name,usr_email);
databaseReference.child("Users").child(user.getUid()).child("name").setValue(name);
databaseReference.child("Users").child(user.getUid()).child("email").setValue(usr_email);
NavigationView navigationView1=(NavigationView)findViewById(R.id.nav_view);
navigationView1.setNavigationItemSelectedListener(this);
View header=navigationView1.getHeaderView(0);
username=(TextView)header.findViewById(R.id.user_name);
email=(TextView)header.findViewById(R.id.user_email_id);
username.setText(name);
email.setText(usr_email);
}
barcoderesult=(TextView)findViewById(R.id.status_text);
}
public void scanBarcode(View view){
Intent intent=new Intent(this,Scan_Barcode.class);
startActivityForResult(intent,0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==0){
if (resultCode== CommonStatusCodes.SUCCESS) {
if (data != null) {
Barcode barcode=data.getParcelableExtra("barcode");
barcoderesult.setText("Barcode Value:"+barcode.displayValue);
// AlertDialog.Builder alertbuilder=new AlertDialog.Builder(Home.this)
Manual_add obj1=new Manual_add();
obj1.increase_quantity(barcode.displayValue,item_quantity);
Toast.makeText(this,"Item added",Toast.LENGTH_SHORT).show();
}else {
barcoderesult.setText("No barcode Found");
}
}
}
else {
super.onActivityResult(requestCode, resultCode, data);
}
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_barcode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if(checkSelfPermission(android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){
scanBarcode(null);
}
else
{
String[] permissionRequested= {Manifest.permission.CAMERA};
requestPermissions(permissionRequested,CAMERA_REQUEST_CODE);
}
}
} else if (id == R.id.nav_logout) {
mAuth.signOut();
}else if(id == R.id.nav_manual_add){
startActivity(new Intent(Home.this,Manual_add.class));
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
XMl Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/user_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
app:srcCompat="#android:drawable/sym_def_app_icon" />
<TextView
android:id="#+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="Android Studio"
android:textSize="18dp"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/user_email_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android.studio#android.com"
android:textSize="14dp"
/>
</LinearLayout>

Related Links

Create a circular bitmap in Android 2.3
I need advice for this project [duplicate]
How to clean variables in an Activity?
Error in configuring virtual box to ADB
PhoneGap PushPlugin installation - Android
How get webview scale in Android 4
Transisting to different link when clicking on imageview android
Android, How to get/set layout parameters?
Unable to resume Activity..java.lang.NullPointerException in Log in Twitter
success in logcat but empty screen
please suggest any library for local db in android [closed]
Pattern for notifying events to Activities and Services at the same time
Holo theme and custom background for my button
Android compilation trouble after adding and removing BlackBerry SDK
How to Get All Memory Path (Internal or External Memory) list in android
Through Phone Gap how to know total size[used+unused] of Sd-card

Categories

HOME
android
turing-machines
fpga
redux-form
package
graphics
replace
opendj
parameters
settings
webix
title
bing-maps
augeas
octave
commonjs
datastage
speech-synthesis
radgridview
favicon
azure-powershell
glyphicons
wolframalpha
google-picker
pyramid
solrcloud
easeljs
epsilon
shared
errbot
gp
nsurl
calculation
corenlp-server
quickfixj
playstation-portable
clickjacking
timing
sessionstorage
numberpicker
attributeerror
android-softkeyboard
outputcache
tcc
placeholder
xmldocument
clang++
optimizely
ovf
lampp
chai-as-promised
spring-integration-sftp
fclose
launchctl
carrot2
aquamacs
reindex
quicktime
oozie-coordinator
branch-prediction
grails-plugin
autosar
hadoop-2.7.2
model-associations
vorpal.js
angular-ui-typeahead
sklearn-pandas
realsense
atan2
avisynth
dllimport
doctype
jdk1.7
sql-server-data-tools
telepat
ms-access-2000
zxspectrum
nodelist
execve
android-vibration
metatrader5
genymotion-call
functional-java
menubar
conditionaltagsupport
scrypt
breakout
code-duplication
inputmismatchexception
rolify
beaker-testing
argouml
wcf-configuration
dajaxice
adobe-media-server
xcelsius
ruby-1.8
ie-compatibility-mode
interprocess
hbm2java
folding
cfwindow
silverlight-oob
linfu-dynamicproxy
flvplayback

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App