I have an app that I want to run on both a phone and a tablet. I have 2 separate layouts (landscape) for both which are essentially the same except for their dimensions.
My question is how do I make the MainActivity.java detect the device that I'm running on and accordingly fire the activity based on the device being used.
I have looked into fragments but I couldn't really understand how to create them nevermind how to use them.
This is my MainActivity.java:
public class MainActivity extends AppCompatActivity {
EditText name;
ImageView oneStar, twoStar, threeStar, fourStar, fiveStar;
Intent intent;
FirebaseDatabase rootNode;
DatabaseReference reference;
public void displayScore() {
intent = new Intent(getApplicationContext(), Score.class);
startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
setContentView(R.layout.activity_main);
final FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
name = findViewById(R.id.editTextTextPersonName);
oneStar = findViewById(R.id.imageView1);
twoStar = findViewById(R.id.imageView2);
threeStar = findViewById(R.id.imageView3);
fourStar = findViewById(R.id.imageView4);
fiveStar = findViewById(R.id.imageView5);
oneStar.setTag(1);
twoStar.setTag(2);
threeStar.setTag(3);
fourStar.setTag(4);
fiveStar.setTag(5);
class OnClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.VALUE, view.getTag().toString());
if (name.length() == 0){
name.setError("Please enter your full name.");
}
else {
name.setError(null);
rootNode = FirebaseDatabase.getInstance();
reference = rootNode.getReference().child("Users");
//Fetch all values
String username = name.getText().toString();
String value = view.getTag().toString();
int rating = Integer.parseInt(value);
UserHelper helper = new UserHelper(username,rating);
reference.push().setValue(helper);
Toast.makeText(MainActivity.this, "Feedback submitted successfully!", Toast.LENGTH_SHORT).show();
sleep(2500);
displayScore();
}
}
}
oneStar.setOnClickListener(new OnClickListener ());
twoStar.setOnClickListener(new OnClickListener ());
threeStar.setOnClickListener(new OnClickListener ());
fourStar.setOnClickListener(new OnClickListener ());
fiveStar.setOnClickListener(new OnClickListener ());
}
}
Any help would be appreciated.
Thanks in advance.