I am new to noSQL database systems. In this app, there are two types of users (Members and Admins) with two different UI. I am using firebase email authentication to register and validating users. Now, Members can register and log in to their respective interface. But how to define admins in firebase and send admins to their interfaces? Thanks
Member login:
Code:
package com.*******************;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class LoginActivity extends AppCompatActivity {
private EditText txtEmailLogin;
private EditText txtPasswordLogin;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
txtEmailLogin= findViewById(R.id.etLoginEmail);
txtPasswordLogin= findViewById(R.id.etLoginPassword);
firebaseAuth=FirebaseAuth.getInstance();
}
public void btnLogin_Click(View v){
final ProgressDialog progressDialog=ProgressDialog.show(LoginActivity.this, "Please Wait...", "Processing...",true);
(firebaseAuth.signInWithEmailAndPassword(txtEmailLogin.getText().toString(), txtPasswordLogin.getText().toString()))
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if (task.isSuccessful()){
Intent i=new Intent(LoginActivity.this, LastOrder.class);
startActivity(i);
}else{
//Log e("ERROR", task.getException().toString());
Toast.makeText(LoginActivity.this, task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}
public void registrationLink_Click(View v){
Intent i=new Intent(LoginActivity.this,RegistrationActivity.class);
startActivity(i);
}
}
Member registration:
Code:
package com.*******************;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class RegistrationActivity extends AppCompatActivity {
private EditText txtEmail;
private EditText txtPassword;
private EditText txtConfirmPassword;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
txtEmail = findViewById(R.id.etEmail);
txtPassword = findViewById(R.id.etPassword);
txtConfirmPassword=findViewById(R.id.etConfirmPassword);
firebaseAuth = FirebaseAuth.getInstance();
}
public void btnSubmit_Click(View v) {
final ProgressDialog progressDialog = ProgressDialog.show(RegistrationActivity.this, "Please Wait...", "Processing...", true);
(firebaseAuth.createUserWithEmailAndPassword(txtEmail.getText().toString(), txtPassword.getText().toString()))
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if (task.isSuccessful()) {
Toast.makeText(RegistrationActivity.this, "Registration Successful", Toast.LENGTH_LONG).show();
Intent i = new Intent(RegistrationActivity.this, LoginActivity.class);
startActivity(i);
} else {
//Log e("ERROR", task.getException().toString());
Toast.makeText(RegistrationActivity.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
public void btnCancel_Click(View v){
Intent i=new Intent(RegistrationActivity.this, LoginActivity.class);
startActivity(i);
}
}
Related
Hey Android experts,
this may be a n00b like question but I'm a beginner to android and i'm struggling with displaying images in a gridview. All i need to do is display the images i have located in res/drawable when clicked on.
I currently have the following code in java
My GridView Class​
package com.example.gridview;
import com.example.helloandroid.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
public class HelloGridView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Where I'm struggling, I just need to find a way to display img048 and img049 from mThumbsIds when clicked on
}
});
}
}
My ImageAdapter class​
package com.example.gridview;
import com.example.helloandroid.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.img048, R.drawable.img049
};
}
Thank you SO MUCH everybody!
Hello XDA,
So I've not found anyone properly discussing this. If they do, please link me to the page and don't flame
I've been making an app for my school and so far, I've been doing alright. But now I have run into a problem which seems to be very hard to solve for me alone.
Namely, I have an EditText and a Button in one Activity and a WebView as a different Activity.
I'm trying to get the EditText String into the WebView URL (String being variable, Button initiating the WebView), but get a lot of errors, some not even related to that.
I would really appreciate it if someone could have a look at the code and help me with this
MyWebView.java:
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebView extends Activity {
WebView mWebView;
EditText mEtxtStudentNum;
static String StudentNumFromHome = bas.sie.Antonius.Home.StudentNum;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://carmelcollegegouda.nl/site_ant/roosters/standaardroosters/Lee1_" + StudentNumFromHome + ".htm");
}
}
Home.java (Homescreen):
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Home extends Activity {
Button mBtnStSchedule;
static EditText mEtxtStudentNum;
static final String StudentNum = mEtxtStudentNum.getText().toString();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.BtnStSchedule);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), MyWebView.class);
startActivityForResult(myIntent, 0);
}
});
// TODO Auto-generated method stub
}
}
AntoniusActivity.java (Main):
Code:
package bas.sie.Antonius;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
public class AntoniusActivity extends TabActivity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Home.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home").setIndicator("Home",
res.getDrawable(R.drawable.ic_tab_home))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, External.class);
spec = tabHost.newTabSpec("external").setIndicator("External",
res.getDrawable(R.drawable.ic_tab_external))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Contact.class);
spec = tabHost.newTabSpec("contact").setIndicator("Contact",
res.getDrawable(R.drawable.ic_tab_contact))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
In AntoniusActivity, the private class HelloWebViewClient is underlined with yellow (never used), specifically the bit "HelloWebViewClient".
It's also throwing FC's at startup, and errors in LogCat, but I'll post those later on, as it's 10.30 PM here, and school goes on
Thanks in advance,
bassie1995
No suggestions yet?
How you doin'? Greetings from my GT-I9000!
I need help in this moment..
my code .
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore.Video;
import android.view.KeyEvent;
import android.view.Window;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.widget.VideoView;
@suppressLint("HandlerLeak")
public class Activity_Splash extends Activity {
ProgressBar progressBar;
protected boolean isRunning;
VideoView myVideoView;
String SrcPath = "/storage/sdcard0/Video/Reik-ConlaCaraenAlto_HD.mp4";
@override
public void onCreate(Bundle savedInstanceState){
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
VideoView myVideoView = (VideoView)findViewById(R.id.videoView1);
myVideoView.setVideoPath(SrcPath);
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(1000);
handler.sendMessage(handler.obtainMessage());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Intent mainIntent = new Intent().setClass(Activity_Splash.this, Activity_Home.class);
startActivity(mainIntent);
finish();
}
}).start();
}
Handler handler=new Handler() {
@override
public void handleMessage(Message msg) {
progressBar.incrementProgressBy(5);
}
};
@override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// Bloquiar la tecla volver para no cerrar el app
Toast.makeText(this, "No puede Retroceder", Toast.LENGTH_SHORT).show();
return false;
}
return super.onKeyDown(keyCode, event);
}
}
how maintain the data when rotate the screen???
Hi,
i have a Listview...click on Listitem open image and text after open full image...pls help full code..
i have a error message :Activity Not Found Exception...Pls sharing the code This i s i wright code... MainActivity.java
package com.example.prj_10;
import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity { ListView list; String[] kkTitles; String[] kkDescriptions; int[] images={R.drawable.anamrama1,R.drawable.aruna2,R.drawable.mukesh3,R.drawable.nagendra4,R.drawable.balaraju5};
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res=getResources();
kkTitles=res.getStringArray(R.array.titles);
kkDescriptions=res.getStringArray(R.array.descriptions);
list=(ListView) findViewById(R.id.listView1);
MainAdapter adapter=new MainAdapter(this,kkTitles,images,kkDescriptions);
list.setAdapter(adapter);
GridView gridView = (GridView) findViewById(R.id.grid_view);
// Instance of ImageAdapter Class
gridView.setAdapter(new ImageAdapter(this));
/**
* On Click event for Single Gridview Item
* */
gridView.setOnItemClickListener(new OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImage.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
}
class MainAdapter extends ArrayAdapter<String>
{
Context context;
int[] images;
String[] titleArray;
String[] descriptionArray;
private ImageView myImage1;
MainAdapter(Context c,String[] titles,int imgs[],String[] desc)
{
super(c,R.layout.activity_main,R.id.textView1,titles);
this.context=c;
this.images=imgs;
this.titleArray=titles;
this.descriptionArray=desc;
}
@override
public View getView(int position,View convertView,ViewGroup parent){
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.activity_main,parent,false);
ImageView myImage1=(ImageView) row.findViewById(R.id.imageView1);
TextView myTitle=(TextView) row.findViewById(R.id.textView1);
TextView myDescription=(TextView) row.findViewById(R.id.textView2);
myImage1.setImageResource(images[position]);
myTitle.setText(titleArray[position]);
myDescription.setText(descriptionArray[position]);
return row;
}
} }
ImageAdapter.java
package com.example.prj_10;
import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter { private Context mContext;
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.anamrama1,
};
// Constructor
public ImageAdapter(Context c){
mContext = c;
}
@override
public int getCount() {
return mThumbIds.length;
}
@override
public Object getItem(int position) {
return mThumbIds[position];
}
@override
public long getItemId(int position) {
return 0;
}
@override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
return imageView;
}
}
FullImage.java
package com.example.prj_10;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.ImageView;
public class FullImage extends Activity {
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view1);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
}
}
activity_main.xml
<ListView
android1:id="@+id/listView1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignParentLeft="true"
android1:layout_alignParentTop="true" >
</ListView>
<GridView
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="150dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="40dp"
android:numColumns="3"
android:gravity="center"
android:stretchMode="columnWidth" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="22dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
package com.example.sameer.vehicletrackingsystem.Fragments;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.sameer.vehicletrackingsystem.R;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class GoogleMapFragment extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap;
String add = "Mandhardev";
String state = "Maharashtra";
String country = "India";
String vehicleNumber = "MH-12 FG-1547";
public GoogleMapFragment() {
// Required empty public constructor
}
@override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_google_map, container, false);
}
@override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.addMarker(new MarkerOptions().position(new LatLng(18.046644, 73.876045)).title(vehicleNumber).snippet(add+", "+state+", "+country));
mMap.getMaxZoomLevel();
mMap.getCameraPosition();
}
}