-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java
85 lines (60 loc) · 2.77 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package android.egypt.Mina.myapp;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements MainFragment.Callback {
boolean mTwoPane ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(isOnline())
{
if (findViewById(R.id.a) != null) {
mTwoPane = true;
} else {
mTwoPane = false;
getSupportFragmentManager().beginTransaction().add(R.id.layoutMain, new MainFragment()).commit();
}
}else
{
Toast.makeText(getApplicationContext(),"Check your internet Connection",Toast.LENGTH_LONG).show();
}
}
private boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();
}
@Override
public void onItemSelected(MovieInfo movieInfo) {
if(!mTwoPane) {
Intent intent = new Intent(this, DetailActivity.class);
intent.putExtra("Tittle", movieInfo.getTittle());
intent.putExtra("Date", movieInfo.getDate());
intent.putExtra("OverView", movieInfo.getOverview());
intent.putExtra("Image", movieInfo.getImageurl());
intent.putExtra("average", (Double.toString(movieInfo.getAverage())));
intent.putExtra("id", (movieInfo.getId()));
Toast.makeText(getApplicationContext(),"Mobile Running",Toast.LENGTH_LONG).show();
startActivity(intent);
}
else {
Toast.makeText(getApplicationContext(),"Tablet Running",Toast.LENGTH_LONG).show();
DetailFragment detailFragment = new DetailFragment();
Bundle bundle = new Bundle();
bundle.putString("Tittle",movieInfo.getTittle());
bundle.putString("Date",movieInfo.getDate());
bundle.putString("OverView",movieInfo.getOverview());
bundle.putString("Image", movieInfo.getImageurl());
bundle.putString("average", String.valueOf(movieInfo.getAverage()));
bundle.putInt("id", movieInfo.getId());
detailFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.belle,detailFragment).commit();
}
}
}